Skip to content

Commit 303551c

Browse files
authored
refactor: disallow inline non-test/priv submodules (#101)
* refactor: remove unneeded consts, move banner fn Remove unnecessary constant definitions, primarily in the banner printing function. Also move out the function from the constants module to its own module `lyra/src/core/banner.rs`. * refactor: disallow inline non-test/priv submodules Disallow inlined submodules those aren't test or private (for sealing trait implementations) modules in other rust modules. Prefer creating rust files in a directory instead. * style: add new lines between exit code constants Also use `#[allow(unused)]` instead of commenting out unused constants and add full stops in their documentation. * refactor: move fuzzy matcher & url regex to statik Move `lyra::src::core::konst::text::FuzzyMatcher` and to `statik/fuzzy_matcher` and `konst::regex::URL` to `statik/regex` as they previously do not belong in the constants module because they are statics. * refactor: rename `konst/colours.rs` to `colour.rs` Rename `lyra/src/core/konst/colours.rs` to `colour.rs`. * chore: update Cargo.lock, flake.lock
1 parent f58722c commit 303551c

File tree

29 files changed

+322
-352
lines changed

29 files changed

+322
-352
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lyra/src/command/poll.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::{
3434
LavalinkAware,
3535
core::{
3636
konst::{
37-
colours,
37+
colour,
3838
poll::{BASE, DOWNVOTE, RATIO_BAR_SIZE, UPVOTE},
3939
},
4040
model::{
@@ -285,9 +285,9 @@ fn generate_upvote_button_id_and_row() -> (String, Component) {
285285
}
286286

287287
fn generate_latent_embed_colours() -> LatentEmbedColours {
288-
let upvote = mixbox::rgb_to_latent(&(hex_to_rgb(colours::UPVOTE)));
289-
let downvote = mixbox::rgb_to_latent(&hex_to_rgb(colours::DOWNVOTE));
290-
let base = mixbox::rgb_to_latent(&hex_to_rgb(colours::POLL_BASE));
288+
let upvote = mixbox::rgb_to_latent(&(hex_to_rgb(colour::UPVOTE)));
289+
let downvote = mixbox::rgb_to_latent(&hex_to_rgb(colour::DOWNVOTE));
290+
let base = mixbox::rgb_to_latent(&hex_to_rgb(colour::POLL_BASE));
291291

292292
LatentEmbedColours {
293293
base,

lyra/src/component/config/access/view.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use twilight_util::builder::embed::EmbedBuilder;
66
use crate::{
77
command::model::{BotGuildSlashCommand, GuildSlashCmdCtx},
88
core::{
9-
konst::colours::EMBED_DEFAULT,
9+
konst::colour::EMBED_DEFAULT,
1010
model::{DatabaseAware, response::initial::message::create::RespondWithMessage},
1111
},
1212
error::CommandResult,

lyra/src/component/queue/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ use crate::{
3535
},
3636
core::{
3737
http::InteractionClient,
38-
konst::{discord::COMMAND_CHOICES_LIMIT, misc::ADD_TRACKS_WRAP_LIMIT, text::FUZZY_MATCHER},
38+
konst::{discord::COMMAND_CHOICES_LIMIT, misc::ADD_TRACKS_WRAP_LIMIT},
3939
model::{
4040
CacheAware,
4141
response::{either::RespondOrFollowup, initial::message::create::RespondWithMessage},
4242
},
43+
statik::fuzzy_matcher::FUZZY_MATCHER,
4344
},
4445
error::{PositionOutOfRange as PositionOutOfRangeError, component::queue::RemoveTracksError},
4546
lavalink::{CorrectTrackInfo, QueueItem},

lyra/src/component/queue/play.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::{
3737
require, util,
3838
},
3939
core::{
40-
konst::{discord::COMMAND_CHOICES_LIMIT, misc::ADD_TRACKS_WRAP_LIMIT, regex},
40+
konst::{discord::COMMAND_CHOICES_LIMIT, misc::ADD_TRACKS_WRAP_LIMIT},
4141
model::{
4242
UserIdAware,
4343
response::{
@@ -48,6 +48,7 @@ use crate::{
4848
},
4949
},
5050
},
51+
statik::regex,
5152
},
5253
error::{
5354
CommandResult, LoadFailed as LoadFailedError,

lyra/src/core/banner.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use aho_corasick::AhoCorasick;
2+
3+
/// Prints the bot's banner.
4+
///
5+
/// This includes the Λύρα icon, cargo package information and build-specific
6+
/// metadata.
7+
pub fn banner() -> String {
8+
// we can afford to initialise the entire banner string without any memoisation,
9+
// as this will only be called once, in `runner::start()`.
10+
11+
let metadata_patterns = [
12+
"%version",
13+
"%authors",
14+
"%copyright",
15+
"%build_timestamp",
16+
"%git_describe",
17+
"%git_sha",
18+
"%git_commit_timestamp",
19+
"%git_branch",
20+
"%rustc_semver",
21+
"%rustc_channel",
22+
"%rustc_host",
23+
"%rustc_commit_hash",
24+
"%cargo_target_triple",
25+
"%cargo_opt_level",
26+
];
27+
28+
let metadata_replacements = [
29+
env!("CARGO_PKG_VERSION"),
30+
env!("CARGO_PKG_AUTHORS"),
31+
env!("CARGO_PKG_LICENSE"),
32+
env!("VERGEN_BUILD_TIMESTAMP"),
33+
env!("VERGEN_GIT_DESCRIBE"),
34+
env!("VERGEN_GIT_SHA"),
35+
env!("VERGEN_GIT_COMMIT_TIMESTAMP"),
36+
env!("VERGEN_GIT_BRANCH"),
37+
env!("VERGEN_RUSTC_SEMVER"),
38+
env!("VERGEN_RUSTC_CHANNEL"),
39+
env!("VERGEN_RUSTC_HOST_TRIPLE"),
40+
env!("VERGEN_RUSTC_COMMIT_HASH"),
41+
env!("VERGEN_CARGO_TARGET_TRIPLE"),
42+
env!("VERGEN_CARGO_OPT_LEVEL"),
43+
];
44+
45+
let rdr = include_str!("../../../assets/lyra2-ascii.ans");
46+
let mut wtr = Vec::new();
47+
48+
let ac = AhoCorasick::new(metadata_patterns).expect("METADATA_PATTERNS must be valid");
49+
ac.try_stream_replace_all(rdr.as_bytes(), &mut wtr, &metadata_replacements)
50+
.expect("searching must be infallible");
51+
String::from_utf8(wtr).expect("interpolated banner must be utf-8")
52+
}

lyra/src/core/konst.rs

Lines changed: 0 additions & 171 deletions
This file was deleted.

lyra/src/core/konst/colour.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub const EMBED_DEFAULT: u32 = 0x82_6b_d6;
2+
pub const DOWNVOTE: u32 = 0xdd_2e_44;
3+
pub const UPVOTE: u32 = 0x58_65_f2;
4+
pub const POLL_BASE: u32 = 0x00_00_00;

lyra/src/core/konst/connection.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use std::time::Duration;
2+
3+
pub const INACTIVITY_TIMEOUT: Duration = Duration::from_secs(600);
4+
pub const CHANGED_TIMEOUT: Duration = Duration::from_millis(250);
5+
pub const GET_LAVALINK_CONNECTION_INFO_TIMEOUT: Duration = Duration::from_millis(2_000);

0 commit comments

Comments
 (0)