-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multi-discord-channel support and much more. chech out /help and RECENT_CHANGES.md
- Loading branch information
1 parent
f8cefd1
commit ffc3269
Showing
14 changed files
with
730 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "nyaa-notifs" | ||
version = "0.1.6" | ||
version = "0.1.7" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
* Attempt to fix multiple threads spawning when the discord bot reconnects | ||
* Discord: If comments are too long, the message will be split and sent in different parts | ||
* Discord: Removed "A new comment!" message for less bloat | ||
* Discord: New releases messages now feature the actual uploaders gravatar instead of nyaa's default one. | ||
* Comments in general: Markdown image embeds are now being stripped to only the url. f.e. `![](http://images.com/i.jpg)` -> `http://images.com/i.jpg` | ||
* Cleaned up code a little bit | ||
* Finally fixed the running loop when the bot gets reconnected | ||
* Multiple discord server support | ||
* Check out `/help` to for setup. | ||
* Make sure the bot has permissions to read/write messages | ||
* Only administrators have permissions to access the commands | ||
|
||
##### slash commands are easy, no need for poise ha |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- Add migration script here | ||
CREATE TABLE FRONT ( | ||
activated TEXT NO NULL, | ||
comments TEXT NO NULL, | ||
releases TEXT NO NULL, | ||
channel_id INTEGER, | ||
urls TEXT NO NULL | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use serenity::model::prelude::command::CommandOptionType; | ||
use serenity::{builder::CreateApplicationCommand, prelude::Context}; | ||
use serenity::model::Permissions; | ||
use serenity::model::prelude::Activity; | ||
use serenity::model::prelude::interaction::application_command::CommandDataOption; | ||
|
||
pub async fn run(options: &[CommandDataOption], ctx: &Context) -> String { | ||
let act = &options.get(0).unwrap().value.as_ref().unwrap().as_str().unwrap(); | ||
ctx.set_activity(Activity::listening(act)).await; | ||
"Activity changed.".to_string() | ||
} | ||
|
||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { | ||
command | ||
.name("activity").description("Change the activity status of the bot.") | ||
.default_member_permissions(Permissions::ADMINISTRATOR) | ||
.create_option(|option| { | ||
option | ||
.name("listens to") | ||
.description("listening to what") | ||
.kind(CommandOptionType::String) | ||
.min_length(2) | ||
.required(true) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use serenity::builder::CreateApplicationCommand; | ||
use serenity::model::Permissions; | ||
use serenity::model::prelude::ChannelId; | ||
use serenity::model::prelude::interaction::application_command::CommandDataOption; | ||
use serenity::model::prelude::command::CommandOptionType; | ||
|
||
use crate::database::{check_for_channel_id, add_discord_channel}; | ||
use crate::DiscordChannel; | ||
|
||
pub async fn run(options: &[CommandDataOption], channel_id: ChannelId) -> String { | ||
let url_input = &options.get(0).unwrap().value.as_ref().unwrap().as_str().unwrap(); | ||
let releases = &options.get(1).unwrap().value.as_ref().unwrap().as_bool().unwrap(); | ||
let comments = &options.get(2).unwrap().value.as_ref().unwrap().as_bool().unwrap(); | ||
let channel_id = channel_id.0 as i64; | ||
if ! check_for_channel_id(channel_id).await.unwrap().is_empty() | ||
{ | ||
return "This discord channel has already been configured, please make sure to `/reset` it before adding new settings.".to_string(); | ||
} | ||
let urls: Vec<String> = url_input.split(", ").map(|str| str.to_string()).collect(); | ||
add_discord_channel(DiscordChannel { | ||
activated: true, | ||
releases: *releases, | ||
comments: *comments, | ||
channel_id, | ||
urls: urls.clone() | ||
}).await.unwrap(); | ||
println!("{:?} configured with {:?} | {} {}", channel_id, urls, releases, comments); | ||
"Channel successfully configured.".to_string() | ||
} | ||
|
||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { | ||
command | ||
.name("create").description("Setup notifications for the current channel") | ||
.create_option(|option| { | ||
option | ||
.name("url") | ||
.description("List of nyaa url's") | ||
.kind(CommandOptionType::String) | ||
.min_length(15) | ||
.required(true) | ||
}) | ||
.create_option(|option| { | ||
option | ||
.name("releases") | ||
.description("Notifications for releases") | ||
.kind(CommandOptionType::Boolean) | ||
.required(true) | ||
}) | ||
.create_option(|option| { | ||
option | ||
.name("comments") | ||
.description("Notifications for comments") | ||
.kind(CommandOptionType::Boolean) | ||
.required(true) | ||
}).default_member_permissions(Permissions::ADMINISTRATOR) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use serenity::builder::CreateApplicationCommand; | ||
use serenity::model::Permissions; | ||
use serenity::model::prelude::interaction::application_command::CommandDataOption; | ||
|
||
pub fn run(_options: &[CommandDataOption]) -> String { | ||
"```\ | ||
[Nyaa-Notifications] | ||
Commands: | ||
\"help\" - Print this help message | ||
\"create\" - Setup notifications for the current channel | ||
\"reset\" - Remove notifications for the current channel | ||
\"pause\" - Pause all notifications for this channel | ||
\"resume\" - Resume all notifications for this channel```".to_string() | ||
} | ||
|
||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { | ||
command.name("help").description("Small description of available commands") | ||
.default_member_permissions(Permissions::ADMINISTRATOR) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod help; | ||
pub mod create; | ||
pub mod reset; | ||
pub mod pause_unpause; | ||
pub mod activity; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use serenity::{builder::CreateApplicationCommand, model::prelude::command::CommandOptionType}; | ||
use serenity::model::Permissions; | ||
use serenity::model::prelude::ChannelId; | ||
use serenity::model::prelude::interaction::application_command::CommandDataOption; | ||
|
||
use crate::database::{check_for_channel_id, update_discord_bot}; | ||
|
||
pub async fn run(options: &[CommandDataOption], channel_id: ChannelId) -> String { | ||
let channel_id = channel_id.0 as i64; | ||
let input = &options.get(0).unwrap().value.as_ref().unwrap().as_bool().unwrap(); | ||
let check = check_for_channel_id(channel_id).await.unwrap(); | ||
if check.is_empty() | ||
{ | ||
return "This discord channel has not been configured yet. Type `/create` to set it up.".to_string(); | ||
} | ||
else if check.get(0).unwrap().activated && ! *input | ||
{ | ||
return "This discord channel is not paused to begin with.\nYou might want to check out `/pause True`.".to_string(); | ||
} | ||
else if ! check.get(0).unwrap().activated && *input | ||
{ | ||
return "This discord channel is already paused.\nYou might want to check out `/pause False`.".to_string(); | ||
} | ||
if *input | ||
{ | ||
update_discord_bot(channel_id, true, false).await.unwrap(); | ||
} | ||
else | ||
{ | ||
update_discord_bot(channel_id, false, false).await.unwrap(); | ||
} | ||
println!("Notifications now {:?} for {:?}", input, channel_id); | ||
"Channel configuration successfully edited.".to_string() | ||
} | ||
|
||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { | ||
command | ||
.name("pause").description("Change the notification-state for the current channel") | ||
.default_member_permissions(Permissions::ADMINISTRATOR) | ||
.create_option(|option| { | ||
option | ||
.name("yesno") | ||
.description("Pause notifications or resume them") | ||
.kind(CommandOptionType::Boolean) | ||
.required(true) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use serenity::builder::CreateApplicationCommand; | ||
use serenity::model::Permissions; | ||
use serenity::model::prelude::ChannelId; | ||
use serenity::model::prelude::interaction::application_command::CommandDataOption; | ||
|
||
use crate::database::{check_for_channel_id, update_discord_bot}; | ||
|
||
pub async fn run(_options: &[CommandDataOption], channel_id: ChannelId) -> String { | ||
let channel_id = channel_id.0 as i64; | ||
if check_for_channel_id(channel_id).await.unwrap().is_empty() | ||
{ | ||
return "This discord channel has not been configured. Type `/create` to set it up.".to_string(); | ||
} | ||
update_discord_bot(channel_id, false, true).await.unwrap(); | ||
println!("Configuration removed for {:?}", channel_id); | ||
"Channel configuration successfully removed.".to_string() | ||
} | ||
|
||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { | ||
command | ||
.name("reset").description("Remove configurations for the current channel") | ||
.default_member_permissions(Permissions::ADMINISTRATOR) | ||
} |
Oops, something went wrong.