Compare commits
21 Commits
Author | SHA1 | Date |
---|---|---|
trivernis | 9bfb35dbce | 11 months ago |
trivernis | 048d6a5cba | 11 months ago |
trivernis | b2b09a3f4f | 11 months ago |
trivernis | e3250e1bc6 | 11 months ago |
trivernis | 2d869f3ea8 | 11 months ago |
trivernis | e6726e41c8 | 11 months ago |
trivernis | bc57733dbf | 11 months ago |
trivernis | 37b22a7d51 | 11 months ago |
trivernis | 6c9889e3e1 | 11 months ago |
trivernis | 8836f311c9 | 11 months ago |
trivernis | 06c8ac2446 | 2 years ago |
trivernis | 84eaf56810 | 2 years ago |
trivernis | 118832036e | 2 years ago |
trivernis | 065fc688ad | 2 years ago |
trivernis | 05aadf615d | 2 years ago |
trivernis | 52a956b2f7 | 2 years ago |
trivernis | 7a70e30c7e | 2 years ago |
Julius Riegel | e23a0bd325 | 2 years ago |
trivernis | 4089cd2305 | 2 years ago |
Julius Riegel | 6c100ad1e5 | 2 years ago |
trivernis | c217e65557 | 2 years ago |
@ -0,0 +1,39 @@
|
||||
version: 1
|
||||
when:
|
||||
- event: [pull_request]
|
||||
- event: push
|
||||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
- release/*
|
||||
- fix/*
|
||||
steps:
|
||||
test:
|
||||
image: rust:alpine
|
||||
commands:
|
||||
- apk add --no-cache --force-overwrite \
|
||||
build-base \
|
||||
openssl-dev \
|
||||
libopusenc-dev \
|
||||
libpq-dev \
|
||||
curl \
|
||||
bash
|
||||
- rustup default stable
|
||||
- rustup component add clippy --toolchain stable-x86_64-unknown-linux-musl
|
||||
- cargo clippy
|
||||
- cargo test --verbose --package bot-coreutils
|
||||
- cargo test --verbose --package bot-database
|
||||
- cargo test --verbose
|
||||
|
||||
build:
|
||||
image: rust:alpine
|
||||
commands:
|
||||
- apk add --no-cache --force-overwrite \
|
||||
build-base \
|
||||
openssl-dev \
|
||||
libopusenc-dev \
|
||||
libpq-dev \
|
||||
curl \
|
||||
bash
|
||||
- cargo build
|
||||
when:
|
||||
- event: [pull_request]
|
@ -0,0 +1,20 @@
|
||||
version: 1
|
||||
when:
|
||||
- event: [tag]
|
||||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
steps:
|
||||
build:
|
||||
image: woodpeckerci/plugin-docker-buildx
|
||||
secrets: [forgejo_token]
|
||||
settings:
|
||||
dockerfile: Containerfile
|
||||
tag: ${CI_COMMIT_TAG##v}
|
||||
repo: git.trivernis.net/trivernis/2b-rs
|
||||
registry: git.trivernis.net
|
||||
platforms: linux/amd64
|
||||
username:
|
||||
from_secret: forgejo_id
|
||||
password:
|
||||
from_secret: forgejo_token
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
use migration::Migrator;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[async_std::main]
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
cli::run_cli(Migrator).await;
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
use serenity::client::Context;
|
||||
use serenity::framework::standard::macros::command;
|
||||
use serenity::framework::standard::CommandResult;
|
||||
use serenity::model::channel::Message;
|
||||
|
||||
use crate::commands::common::handle_autodelete;
|
||||
use crate::providers::music::lavalink::Lavalink;
|
||||
use crate::utils::initialize_lavalink;
|
||||
use serenity_rich_interaction::core::SHORT_TIMEOUT;
|
||||
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
|
||||
use std::mem;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[command]
|
||||
#[description("Resets the lavalink connection")]
|
||||
#[aliases("reconnect_lavalink", "reset-lavalink", "reconnect-lavalink")]
|
||||
#[num_args(0)]
|
||||
#[owners_only]
|
||||
async fn reset_lavalink(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
let app_info = ctx.http.get_current_application_info().await?;
|
||||
destroy_lavalink(ctx).await;
|
||||
|
||||
initialize_lavalink(Arc::clone(&ctx.data), app_info).await?;
|
||||
|
||||
EphemeralMessage::create(&ctx.http, msg.channel_id, SHORT_TIMEOUT, |m| {
|
||||
m.content("Reconnected to lavalink")
|
||||
})
|
||||
.await?;
|
||||
handle_autodelete(ctx, msg).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn destroy_lavalink(ctx: &Context) {
|
||||
let mut data = ctx.data.write().await;
|
||||
{
|
||||
let lava_client = data.remove::<Lavalink>().unwrap();
|
||||
mem::drop(lava_client);
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
use serenity::framework::standard::macros::command;
|
||||
use serenity::framework::standard::{Args, CommandError, CommandResult};
|
||||
use serenity::model::channel::Message;
|
||||
use serenity::prelude::*;
|
||||
|
||||
use crate::commands::common::handle_autodelete;
|
||||
use crate::commands::music::{get_music_player_for_guild, DJ_CHECK};
|
||||
use crate::messages::music::no_voicechannel::create_no_voicechannel_message;
|
||||
use serenity_rich_interaction::core::{MEDIUM_TIMEOUT, SHORT_TIMEOUT};
|
||||
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
|
||||
|
||||
#[command]
|
||||
#[only_in(guilds)]
|
||||
#[description("Loads an equalizer preset")]
|
||||
#[usage("<preset>")]
|
||||
#[num_args(1)]
|
||||
#[example("bass")]
|
||||
#[bucket("general")]
|
||||
#[checks(DJ)]
|
||||
async fn equalize(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
let guild = msg.guild(&ctx.cache).await.unwrap();
|
||||
tracing::debug!("Changing equalizer for {}", guild.id);
|
||||
let preset = args.single::<String>().unwrap();
|
||||
|
||||
let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await {
|
||||
player
|
||||
} else {
|
||||
return create_no_voicechannel_message(&ctx.http, msg.channel_id)
|
||||
.await
|
||||
.map_err(CommandError::from);
|
||||
};
|
||||
|
||||
let bands = match preset.to_lowercase().as_str() {
|
||||
"metal" => lavalink_rs::EQ_METAL,
|
||||
"boost" => lavalink_rs::EQ_BOOST,
|
||||
"base" => lavalink_rs::EQ_BASE,
|
||||
"piano" => lavalink_rs::EQ_PIANO,
|
||||
_ => {
|
||||
EphemeralMessage::create(&ctx.http, msg.channel_id, MEDIUM_TIMEOUT, |m| {
|
||||
m.content(format!(
|
||||
"Unknown preset '{}'. Available are 'metal', 'boost', 'base' and 'piano'",
|
||||
preset
|
||||
))
|
||||
})
|
||||
.await?;
|
||||
handle_autodelete(ctx, msg).await?;
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
{
|
||||
let mut player = player.lock().await;
|
||||
player.equalize_all(bands).await?;
|
||||
}
|
||||
EphemeralMessage::create(&ctx.http, msg.channel_id, SHORT_TIMEOUT, |m| {
|
||||
m.content(format!("🎛️ Changed equalizer to '{}'", preset))
|
||||
})
|
||||
.await?;
|
||||
|
||||
handle_autodelete(ctx, msg).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
use serenity::framework::standard::macros::command;
|
||||
use serenity::framework::standard::{CommandError, CommandResult};
|
||||
use serenity::model::channel::Message;
|
||||
use serenity::prelude::*;
|
||||
|
||||
use crate::commands::common::handle_autodelete;
|
||||
use crate::commands::music::{get_music_player_for_guild, DJ_CHECK};
|
||||
use crate::messages::music::equalizer::create_equalizer_message;
|
||||
use crate::messages::music::no_voicechannel::create_no_voicechannel_message;
|
||||
|
||||
#[command]
|
||||
#[only_in(guilds)]
|
||||
#[description("Displays the equalizer for the music player")]
|
||||
#[usage("")]
|
||||
#[bucket("general")]
|
||||
#[checks(DJ)]
|
||||
async fn equalizer(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
let guild = msg.guild(&ctx.cache).await.unwrap();
|
||||
tracing::debug!("Displaying equalizer for guild {}", guild.id);
|
||||
|
||||
let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await {
|
||||
player
|
||||
} else {
|
||||
return create_no_voicechannel_message(&ctx.http, msg.channel_id)
|
||||
.await
|
||||
.map_err(CommandError::from);
|
||||
};
|
||||
|
||||
create_equalizer_message(&ctx, msg.channel_id, player).await?;
|
||||
handle_autodelete(ctx, msg).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
pub mod equalizer;
|
||||
pub mod no_voicechannel;
|
||||
pub mod now_playing;
|
||||
pub mod queue;
|
||||
|
@ -1,53 +0,0 @@
|
||||
use crate::utils::context_data::MusicPlayers;
|
||||
use lavalink_rs::gateway::LavalinkEventHandler;
|
||||
use lavalink_rs::model::{PlayerUpdate, Stats, TrackFinish, TrackStart};
|
||||
use lavalink_rs::LavalinkClient;
|
||||
use serenity::async_trait;
|
||||
use serenity::prelude::TypeMapKey;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
use typemap_rev::TypeMap;
|
||||
|
||||
pub struct LavalinkHandler {
|
||||
pub data: Arc<RwLock<TypeMap>>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl LavalinkEventHandler for LavalinkHandler {
|
||||
async fn track_start(&self, _client: LavalinkClient, event: TrackStart) {
|
||||
tracing::info!("Track started!\nGuild: {}", event.guild_id);
|
||||
}
|
||||
|
||||
async fn track_finish(&self, _: LavalinkClient, event: TrackFinish) {
|
||||
tracing::info!("Track finished!\nGuild: {}", event.guild_id);
|
||||
let player = {
|
||||
let data = self.data.read().await;
|
||||
let players = data.get::<MusicPlayers>().unwrap();
|
||||
|
||||
players.get(&event.guild_id.0).cloned()
|
||||
};
|
||||
if let Some(player) = player {
|
||||
let mut player = player.lock().await;
|
||||
if let Err(e) = player.play_next().await {
|
||||
tracing::error!("Failed to play next song: {:?}", e);
|
||||
}
|
||||
if let Err(e) = player.update_now_playing().await {
|
||||
tracing::error!("Failed to update now playing embed: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn player_update(&self, _: LavalinkClient, event: PlayerUpdate) {
|
||||
tracing::debug!("Received player update event: {:?}", event);
|
||||
}
|
||||
|
||||
async fn stats(&self, _: LavalinkClient, event: Stats) {
|
||||
tracing::debug!("Received stats event: {:?}", event);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Lavalink;
|
||||
|
||||
impl TypeMapKey for Lavalink {
|
||||
type Value = Arc<LavalinkClient>;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
use serenity::async_trait;
|
||||
use std::sync::Arc;
|
||||
|
||||
use serenity::prelude::Mutex;
|
||||
use songbird::{Call, Event, EventContext, EventHandler, TrackEvent};
|
||||
|
||||
use super::player::MusicPlayer;
|
||||
|
||||
pub fn register_player_events(player: Arc<Mutex<MusicPlayer>>, handler: &mut Call) {
|
||||
handler.add_global_event(Event::Track(TrackEvent::End), TrackEndHandler { player });
|
||||
}
|
||||
|
||||
struct TrackEndHandler {
|
||||
player: Arc<Mutex<MusicPlayer>>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for TrackEndHandler {
|
||||
#[tracing::instrument(level = "debug", skip_all)]
|
||||
async fn act(&self, _ctx: &EventContext<'_>) -> Option<Event> {
|
||||
let mut player = self.player.lock().await;
|
||||
if let Err(e) = player.play_next().await {
|
||||
tracing::error!("Failed to play next song: {:?}", e);
|
||||
}
|
||||
if let Err(e) = player.update_now_playing().await {
|
||||
tracing::error!("Failed to update now playing embed: {:?}", e);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue