+2
-1
@@ -4,7 +4,8 @@ Cargo.lock
|
|||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
*.pdb
|
*.pdb
|
||||||
**/__pycache__/
|
**/__pycache__/
|
||||||
.vscode/
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
|
||||||
# program-created data
|
# program-created data
|
||||||
**/reddit_data.json
|
**/reddit_data.json
|
||||||
|
|||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"editor.tabSize": 2,
|
||||||
|
"editor.insertSpaces": true,
|
||||||
|
"editor.detectIndentation": false
|
||||||
|
}
|
||||||
@@ -34,9 +34,9 @@ add_post = ["weekly_art", "weekly"]
|
|||||||
# Disabled selected command categories. All commands and their categories can be viewed in the README.
|
# Disabled selected command categories. All commands and their categories can be viewed in the README.
|
||||||
disabled_categories = [
|
disabled_categories = [
|
||||||
# "fun",
|
# "fun",
|
||||||
# "help"
|
# "help",
|
||||||
# "re"
|
# "re",
|
||||||
# "debug"
|
# "debug",
|
||||||
# "db"
|
# "db"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
"servers": {
|
"servers": {
|
||||||
"SERVER ID": {
|
"SERVER ID": {
|
||||||
"re_posts_channel": 0,
|
"re_posts_channel": 0,
|
||||||
"re_disabled": false
|
"re_disabled": false,
|
||||||
|
"wwrps_channel": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+12
-4
@@ -7,10 +7,10 @@
|
|||||||
"dc_btn_vote": "Vote",
|
"dc_btn_vote": "Vote",
|
||||||
"dc_msg_8-ball_answer": "**8-ball Question:** {0}\n**Answer:** {1}",
|
"dc_msg_8-ball_answer": "**8-ball Question:** {0}\n**Answer:** {1}",
|
||||||
"dc_msg_add_to_data": "Added your server to my data! Thanks for letting me steal it! (/s)",
|
"dc_msg_add_to_data": "Added your server to my data! Thanks for letting me steal it! (/s)",
|
||||||
"dc_msg_bound_channel": "Successfully bound channel ID `{0}` as the \"where all collected Reddit data gets dumped\" channel!",
|
"dc_msg_bound_channel": "Successfully added channel ID `{0}` to the database!",
|
||||||
"dc_msg_cmd_404": "No command \"{0}\" found!\nHint: Try `/help` without any arguments or `/help <category>`",
|
"dc_msg_cmd_404": "No command \"{0}\" found!\nHint: Try `/help` without any arguments or `/help <category>`",
|
||||||
"dc_msg_corrupted_data": "Oopsies `(。>\\\\<)`. It looks like my data i-is \\**sob*\\*... c-corrupted!\n[From Byte Dice]: I have no idea what I was thinking while writing this at 2am. I'm not removing it.",
|
"dc_msg_corrupted_data": "Oopsies `(。>\\\\<)`. It looks like my data i-is \\**sob*\\*... c-corrupted!",
|
||||||
"dc_msg_data_server_404": "This server is not in the data!\n Hint: Run the command `/add_server` inside of a Discord server (requires administrator permission).",
|
"dc_msg_data_server_404": "This server is not in the data!\n Hint: Run the command `/database AddServer` inside of a Discord server (requires administrator permission).",
|
||||||
"dc_msg_dm_python_err_socket": "Unknown internal Python error occurred: Websocket response error",
|
"dc_msg_dm_python_err_socket": "Unknown internal Python error occurred: Websocket response error",
|
||||||
"dc_msg_dm_python_err": "Unknown internal Python Error:\n```\n{0}\n```",
|
"dc_msg_dm_python_err": "Unknown internal Python Error:\n```\n{0}\n```",
|
||||||
"dc_msg_embed_default_embed_desc": "Default english embed description.",
|
"dc_msg_embed_default_embed_desc": "Default english embed description.",
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
"dc_msg_re_post_unremove_success": "Successfully restored post with URL \"<{0}>\"!",
|
"dc_msg_re_post_unremove_success": "Successfully restored post with URL \"<{0}>\"!",
|
||||||
"dc_msg_re_post_update_success": "Updated post with URL \"<{0}>\"!",
|
"dc_msg_re_post_update_success": "Updated post with URL \"<{0}>\"!",
|
||||||
"dc_msg_re_post_vote_removed_post": "Couldn't [vote / un-vote] the post because it has been removed!",
|
"dc_msg_re_post_vote_removed_post": "Couldn't [vote / un-vote] the post because it has been removed!",
|
||||||
"dc_msg_re_posts_channel_404": "Could not find `re_posts_channel` in data!\nHint: Run `/admin_re_bindchannel` in a (preferably read-only) channel (requires administrator permission).",
|
"dc_msg_re_posts_channel_404": "Could not find `re_posts_channel` in data!\nHint: Run `/database RedditChannel` in a (preferably read-only) channel (requires administrator permission).",
|
||||||
"dc_msg_re_vote_err": "Failed to [vote / un-vote]: Unknown internal error.",
|
"dc_msg_re_vote_err": "Failed to [vote / un-vote]: Unknown internal error.",
|
||||||
"dc_msg_re_vote_mod_success": "Successfully voted (as moderator vote)!",
|
"dc_msg_re_vote_mod_success": "Successfully voted (as moderator vote)!",
|
||||||
"dc_msg_re_vote_remove_havent": "Couldn't remove your vote: You haven't voted on this post yet!",
|
"dc_msg_re_vote_remove_havent": "Couldn't remove your vote: You haven't voted on this post yet!",
|
||||||
@@ -58,6 +58,14 @@
|
|||||||
"dc_msg_update_removing_old": "{0}Removing old posts (threshold: {1}d)...",
|
"dc_msg_update_removing_old": "{0}Removing old posts (threshold: {1}d)...",
|
||||||
"dc_msg_update_removing": "{0}Removing removed posts...",
|
"dc_msg_update_removing": "{0}Removing removed posts...",
|
||||||
"dc_msg_whoami": "**Bot \"owner\":** {0}\n**BK moderator:** {1}",
|
"dc_msg_whoami": "**Bot \"owner\":** {0}\n**BK moderator:** {1}",
|
||||||
|
"dc_msg_wwrps_already_submitted": "You can't compete against yourself! Please wait until another player has submitted their RPS.",
|
||||||
|
"dc_msg_wwrps_anon": "[Anonymous]",
|
||||||
|
"dc_msg_wwrps_draw": "DRAW",
|
||||||
|
"dc_msg_wwrps_fight": "### {0} (P1) vs {1} (P2)...\n## {2}\n**P1:** {3}\n**P2:** {4}",
|
||||||
|
"dc_msg_wwrps_not_in_data": "Could not find `wwrps_channel` in data!\nHint: Run `/database WWRPSChannel` in a channel (requires administrator permission).",
|
||||||
|
"dc_msg_wwrps_p1_win": "P1 WINS",
|
||||||
|
"dc_msg_wwrps_p2_win": "P2 WINS",
|
||||||
|
"dc_msg_wwrps_submitting": "Submitting your RPS... Please wait for another contestant to compete against you.",
|
||||||
"log_lang_load_success": "Successfully loaded the english language file!",
|
"log_lang_load_success": "Successfully loaded the english language file!",
|
||||||
"none": "None",
|
"none": "None",
|
||||||
"py_re_response_suffix": "^(I am not an AI, I am just a bot. This action was performed automatically by the way. You can report bugs and view my source code [here](https://github.com/ByteDice/ByteDiceAssistant)!)",
|
"py_re_response_suffix": "^(I am not an AI, I am just a bot. This action was performed automatically by the way. You can report bugs and view my source code [here](https://github.com/ByteDice/ByteDiceAssistant)!)",
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
{
|
|
||||||
"dc_btn_approve": "Approuver",
|
|
||||||
"dc_btn_remove": "Supprimer",
|
|
||||||
"dc_btn_unapprove": "Désapprouver",
|
|
||||||
"dc_btn_unremove": "Restaurer",
|
|
||||||
"dc_btn_unvote": "Annuler le vote",
|
|
||||||
"dc_btn_vote": "Voter",
|
|
||||||
"dc_msg_8-ball_answer": "**Question de la boule magique :** {0}\n**Réponse :** {1}",
|
|
||||||
"dc_msg_add_to_data": "Serveur ajouté à mes données ! Merci de me laisser les voler ! (/s)",
|
|
||||||
"dc_msg_bound_channel": "Canal avec l’identifiant `{0}` lié avec succès comme canal \"où toutes les données Reddit collectées sont envoyées\" !",
|
|
||||||
"dc_msg_cmd_404": "Commande \"{0}\" introuvable !\nAstuce : Essayez `/help` sans arguments ou `/help <catégorie>`",
|
|
||||||
"dc_msg_corrupted_data": "Oups `(。>\\\\<)`. On dirait que mes données sont \\**snif*\\*... c-corrompues !\n[De Byte Dice] : Je n’ai aucune idée de ce que je faisais à 2h du matin. Je ne le supprime pas.",
|
|
||||||
"dc_msg_data_server_404": "Ce serveur n’est pas dans les données !\n Astuce : Exécutez la commande `/add_server` dans un serveur Discord (nécessite les droits administrateur).",
|
|
||||||
"dc_msg_dm_python_err_socket": "Erreur Python interne inconnue : erreur de réponse WebSocket",
|
|
||||||
"dc_msg_dm_python_err": "Erreur Python interne inconnue :\n```\n{0}\n```",
|
|
||||||
"dc_msg_embed_default_embed_desc": "Description par défaut de l'encart en anglais.",
|
|
||||||
"dc_msg_embed_re_post": "Spoilers et anonymiseur de durée des votes pour une évaluation équitable !\n## Données du post :\n**Subreddit :** {0}\n**Votes positifs du post :** ||`{1:>6}`||\n**Votes des modérateurs :** ||`{2:>6}`||\n**Type de média :** `{3}`\n## Données d'inscription :\n**Ajouté par :** humain : {4} | bot : {5}\n**Approuvé:** {6}",
|
|
||||||
"dc_msg_embed_re_removed": "## Supprimé par `{0}`\n**Raison :** {1}",
|
|
||||||
"dc_msg_err_trace": "Erreur inconnue !\nTrace de l’erreur : {0}",
|
|
||||||
"dc_msg_failed_shorturl_conversion": "Échec de la conversion en shortURL : format d’URL Reddit invalide.",
|
|
||||||
"dc_msg_mandatory_response": "Message de réponse obligatoire, merci d’ignorer.",
|
|
||||||
"dc_msg_no_perms": "Permission manquante sur ce serveur : {0}",
|
|
||||||
"dc_msg_not_in_guild": "Je ne fais pas partie de ce serveur.",
|
|
||||||
"dc_msg_owner_data_save_complete": "Sauvegarde des données... Terminé !\nFermeture...",
|
|
||||||
"dc_msg_owner_data_save": "Sauvegarde des données...",
|
|
||||||
"dc_msg_owner_shutdown_failed_confirmation": "Échec de l’arrêt : confirmation invalide.",
|
|
||||||
"dc_msg_re_already_voted": "Impossible de voter : vous avez déjà voté pour ce post !",
|
|
||||||
"dc_msg_re_also_approved": "Également approuvé !",
|
|
||||||
"dc_msg_re_data_corrupted": "URL du post \"<{0}>\" introuvable : données du post corrompues !\n Détails : clé \"posts\" introuvable dans le fichier \"re_data.json\"",
|
|
||||||
"dc_msg_re_help_removed": "Fichier d’aide Reddit introuvable, il a probablement été supprimé.\n Astuce : Vous pouvez trouver le fichier d’aide officiel à https://github.com/ByteDice/ByteDiceAssistant dans `re_help.md`.\n**ATTENTION :** Le fichier d’aide peut contenir des informations incorrectes si vous n’utilisez pas le bot officiel de Byte Dice.",
|
|
||||||
"dc_msg_re_permdeny_not_re_mod": "Permission refusée : vous n’êtes pas modérateur des subreddit(s) {0}",
|
|
||||||
"dc_msg_re_post_404": "URL du post \"<{0}>\" introuvable : le post n’existe pas dans les données !\n Astuce : Exécutez la commande `/re_addpost [URL]` dans un canal Discord ou `u/ByteDiceAssistant add_post` sur un post Reddit.",
|
|
||||||
"dc_msg_re_post_add_success": "Post ajouté avec succès à l’URL \"<{0}>\" !",
|
|
||||||
"dc_msg_re_post_approve_remove": "Impossible d’approuver le post car il a été supprimé !",
|
|
||||||
"dc_msg_re_post_approve_success": "Post approuvé avec succès !",
|
|
||||||
"dc_msg_re_post_disapprove_success": "Post désapprouvé avec succès !",
|
|
||||||
"dc_msg_re_post_remove_success": "Post supprimé avec succès à l’URL \"<{0}>\" !",
|
|
||||||
"dc_msg_re_post_unremove_success": "Post restauré avec succès à l’URL \"<{0}>\" !",
|
|
||||||
"dc_msg_re_post_update_success": "Post mis à jour avec succès à l’URL \"<{0}>\" !",
|
|
||||||
"dc_msg_re_post_vote_removed_post": "Impossible de [voter / annuler le vote] : le post a été supprimé !",
|
|
||||||
"dc_msg_re_posts_channel_404": "Impossible de trouver `re_posts_channel` dans les données !\nAstuce : Exécutez `/admin_re_bindchannel` dans un canal (de préférence en lecture seule) (nécessite les droits administrateur).",
|
|
||||||
"dc_msg_re_vote_err": "Échec du [vote / annulation du vote] : erreur interne inconnue.",
|
|
||||||
"dc_msg_re_vote_mod_success": "Vote enregistré avec succès (vote modérateur) !",
|
|
||||||
"dc_msg_re_vote_remove_havent": "Impossible de retirer le vote : vous n’avez pas encore voté pour ce post !",
|
|
||||||
"dc_msg_re_vote_remove_success": "Vote retiré avec succès !",
|
|
||||||
"dc_msg_re_vote_success": "Vote enregistré avec succès !",
|
|
||||||
"dc_msg_reload_cfg_python_fail": "Échec du rechargement des configurations : réponse invalide de Python.",
|
|
||||||
"dc_msg_reload_cfg_success": "Configurations rechargées avec succès !\nNouvelles configurations :\n```\n{0}\n```",
|
|
||||||
"dc_msg_removed_square_brackets": "[SUPPRIMÉ] {0}",
|
|
||||||
"dc_msg_shorturl": "ShortURL : <{0}>",
|
|
||||||
"dc_msg_update_add": "{0}Ajout de nouveaux posts...",
|
|
||||||
"dc_msg_update_done": "{0}Terminé !",
|
|
||||||
"dc_msg_update_editing": "{0}Modification des posts mis à jour...",
|
|
||||||
"dc_msg_update_fetch": "{0}Récupération des nouveaux posts et mise à jour du fichier de données...",
|
|
||||||
"dc_msg_update_parse": "{0}Analyse des messages vers JSON...",
|
|
||||||
"dc_msg_update_read": "{0}Lecture des messages dans <#{1}>...",
|
|
||||||
"dc_msg_update_removing_dupe": "{0}Suppression des posts en double...",
|
|
||||||
"dc_msg_update_removing_old": "{0}Suppression des anciens posts (seuil : {1}j)...",
|
|
||||||
"dc_msg_update_removing": "{0}Suppression des posts supprimés...",
|
|
||||||
"dc_msg_whoami": "**Propriétaire du bot :** {0}\n**Modérateur BK :** {1}",
|
|
||||||
"log_lang_load_success": "Fichier de langue français chargé avec succès !",
|
|
||||||
"none": "Aucun",
|
|
||||||
"py_re_response_suffix": "^(Je ne suis pas une IA, juste un bot. Cette action a été effectuée automatiquement. Vous pouvez signaler des bugs et consulter mon code source [ici](https://github.com/ByteDice/ByteDiceAssistant) !)",
|
|
||||||
"py_re_response_weekly_add": "Post ajouté avec succès aux soumissions hebdomadaires d'art ! Merci pour votre participation !",
|
|
||||||
"py_re_response_weekly_exists": "Impossible d’ajouter ce post, il est déjà présent ! Merci pour votre participation !",
|
|
||||||
"py_re_response_weekly_mod_add": "[ACTION MOD] Post ajouté avec succès aux soumissions hebdomadaires d’art !",
|
|
||||||
"py_re_response_weekly_mod_unremove": "[ACTION MOD] Post restauré avec succès dans les soumissions hebdomadaires d’art !",
|
|
||||||
"dc_msg_success": "succès !"
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use poise::serenity_prelude::{ChannelId, Mentionable, User};
|
||||||
|
use tokio::sync::MutexGuard;
|
||||||
|
|
||||||
|
use crate::{Context, Error, data::get_mutex_data, lang, messages::{http_send_msg, send_msg}};
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(poise::ChoiceParameter, PartialEq, Clone, Debug)]
|
||||||
|
#[repr(u8)]
|
||||||
|
pub enum RPS {
|
||||||
|
Paper = 0,
|
||||||
|
Rock = 1,
|
||||||
|
Scissors = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct RPSPlayer {
|
||||||
|
pub selection: RPS,
|
||||||
|
pub user: User,
|
||||||
|
pub anonymous: bool
|
||||||
|
}
|
||||||
|
pub struct RPSGame {
|
||||||
|
pub players: [Option<RPSPlayer>; 2],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl Display for RPS {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
return match self {
|
||||||
|
Self::Paper => write!(f, "Paper"),
|
||||||
|
Self::Rock => write!(f, "Rock"),
|
||||||
|
Self::Scissors => write!(f, "Scissors")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl RPSGame {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
return RPSGame {
|
||||||
|
players: [None, None],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns wether the lobby is filled or not
|
||||||
|
pub fn add_player(&mut self, player: RPSPlayer) -> Result<bool, Error> {
|
||||||
|
if let Some(p1) = &self.players[0]
|
||||||
|
{ if p1.user == player.user { return Err(Error::from("Cannot add player, it already exists!")); }}
|
||||||
|
|
||||||
|
if self.players[0].is_none() { self.players[0] = Some(player); return Ok(false); }
|
||||||
|
else if self.players[1].is_none() { self.players[1] = Some(player); return Ok(true); }
|
||||||
|
else { return Err(Error::from("Cannot add player, list is full!")); }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear(&mut self)
|
||||||
|
{ self.players = [None, None]; }
|
||||||
|
|
||||||
|
|
||||||
|
pub fn get_winner(&self) -> Option<i8> {
|
||||||
|
if self.players.iter().any(|i| i.is_none())
|
||||||
|
{ return None; }
|
||||||
|
|
||||||
|
let Some(p1) = self.players[0].clone() else { return None; };
|
||||||
|
let Some(p2) = self.players[1].clone() else { return None; };
|
||||||
|
|
||||||
|
let i1 = p1.selection as u8;
|
||||||
|
let i2 = p2.selection as u8;
|
||||||
|
|
||||||
|
if i1 == i2 { return None; }
|
||||||
|
else if (i1 + 1) % 3 == i2 { return Some(0); }
|
||||||
|
else { return Some(1); }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_full_lobby(&self) -> bool
|
||||||
|
{ return self.players.iter().all(|i| i.is_some()); }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[poise::command(
|
||||||
|
slash_command,
|
||||||
|
prefix_command,
|
||||||
|
category = "fun",
|
||||||
|
rename = "wwrps",
|
||||||
|
required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL"
|
||||||
|
)]
|
||||||
|
/// World-Wide Rock Paper Scissors. Play with a completely random person!
|
||||||
|
pub async fn cmd(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
selection: RPS,
|
||||||
|
#[description = "If true, replaces your username with [Anonymous]."] anonymous: bool
|
||||||
|
) -> Result<(), Error>
|
||||||
|
{
|
||||||
|
let c_o = get_wwrps_channel(ctx).await;
|
||||||
|
|
||||||
|
if c_o.is_none() { send_msg(ctx, lang!("dc_msg_wwrps_not_in_data"), true, true).await; return Ok(()); }
|
||||||
|
let c = c_o.unwrap();
|
||||||
|
|
||||||
|
send_msg(ctx, lang!("dc_msg_wwrps_submitting"), true, true).await;
|
||||||
|
|
||||||
|
let mut game = ctx.data().rps_game.lock().await;
|
||||||
|
|
||||||
|
if !game.is_full_lobby() {
|
||||||
|
let r = game.add_player(
|
||||||
|
RPSPlayer { selection, user: ctx.author().clone(), anonymous });
|
||||||
|
|
||||||
|
if let Err(_) = r
|
||||||
|
{ send_msg(ctx, lang!("dc_msg_wwrps_already_submitted"), true, true).await; return Ok(()); }
|
||||||
|
|
||||||
|
let full = r.unwrap();
|
||||||
|
if !full { return Ok(()); }
|
||||||
|
|
||||||
|
let r_text = results_text(&game);
|
||||||
|
game.clear();
|
||||||
|
|
||||||
|
http_send_msg(ctx.http(), ChannelId::new(c), r_text).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn results_text(game: &MutexGuard<'_, RPSGame>) -> String {
|
||||||
|
let winner = game.get_winner();
|
||||||
|
let winner_text: String;
|
||||||
|
|
||||||
|
if let Some(w) = winner
|
||||||
|
{ winner_text = if w == 0 { lang!("dc_msg_wwrps_p1_win") } else { lang!("dc_msg_wwrps_p2_win") }; }
|
||||||
|
else { winner_text = lang!("dc_msg_wwrps_draw"); }
|
||||||
|
|
||||||
|
let p1 = game.players[0].as_ref().unwrap();
|
||||||
|
let p2 = game.players[1].as_ref().unwrap();
|
||||||
|
let p1_n = if !p1.anonymous { p1.user.mention().to_string() } else { lang!("dc_msg_wwrps_anon") };
|
||||||
|
let p2_n = if !p2.anonymous { p2.user.mention().to_string() } else { lang!("dc_msg_wwrps_anon") };
|
||||||
|
|
||||||
|
return lang!("dc_msg_wwrps_fight", p1.selection.clone(), p2.selection.clone(), winner_text, p1_n, p2_n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async fn get_wwrps_channel(ctx: Context<'_>) -> Option<u64> {
|
||||||
|
let d = get_mutex_data(&ctx.data().discord_data).await.unwrap();
|
||||||
|
|
||||||
|
let is_guild = ctx.guild_channel().await.is_some();
|
||||||
|
|
||||||
|
if !is_guild { return Some(ctx.channel_id().get()); }
|
||||||
|
|
||||||
|
let Some(servers) = d.get("servers") else { return None; };
|
||||||
|
let Some(s) = servers.get(ctx.guild_id().unwrap().get().to_string()) else { return None; };
|
||||||
|
let Some(c_id) = s.get("wwrps_channel") else { return None; };
|
||||||
|
|
||||||
|
return Some(c_id.as_u64().unwrap());
|
||||||
|
}
|
||||||
+21
-1
@@ -20,6 +20,7 @@ static PRESET_PATH_CFG: &str = "./data/defaults/cfg_default.toml";
|
|||||||
static DATA_PATH_LANG: &str = "./data/lang/";
|
static DATA_PATH_LANG: &str = "./data/lang/";
|
||||||
|
|
||||||
pub static DC_POSTS_CHANNEL_KEY: &str = "re_posts_channel";
|
pub static DC_POSTS_CHANNEL_KEY: &str = "re_posts_channel";
|
||||||
|
pub static DC_WWRPS_CHANNEL_KEY: &str = "wwrps_channel";
|
||||||
|
|
||||||
|
|
||||||
pub async fn read_dc_data(data: &Data, wipe: bool) {
|
pub async fn read_dc_data(data: &Data, wipe: bool) {
|
||||||
@@ -154,7 +155,7 @@ pub async fn dc_add_server(data: &Data, server_id: u64) -> Result<(), ()> {
|
|||||||
let servers = dc_data["servers"].as_object_mut().unwrap();
|
let servers = dc_data["servers"].as_object_mut().unwrap();
|
||||||
|
|
||||||
if !servers.contains_key(&server_id.to_string()) {
|
if !servers.contains_key(&server_id.to_string()) {
|
||||||
servers.insert(server_id.to_string(), json!({ DC_POSTS_CHANNEL_KEY: 0 }));
|
servers.insert(server_id.to_string(), json!({}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -181,6 +182,25 @@ pub async fn dc_bind_bk(data: &Data, server_id: u64, channel_id: u64) -> Result<
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub async fn bind_wwrps(data: &Data, server_id: u64, channel_id: u64) -> Result<(), ()> {
|
||||||
|
let mut dc_data_lock = data.discord_data.lock().await;
|
||||||
|
let dc_data = dc_data_lock.as_mut().unwrap();
|
||||||
|
|
||||||
|
if dc_data.get("servers").is_none() { return Err(()); }
|
||||||
|
|
||||||
|
let servers = dc_data["servers"].as_object_mut().unwrap();
|
||||||
|
|
||||||
|
if !servers.contains_key(&server_id.to_string())
|
||||||
|
{ return Err(()); }
|
||||||
|
|
||||||
|
let server = servers[&server_id.to_string()].as_object_mut().unwrap();
|
||||||
|
|
||||||
|
server.insert(DC_WWRPS_CHANNEL_KEY.to_string(), channel_id.into());
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn dc_contains_server(data: &Data, server_id: u64) -> bool {
|
pub async fn dc_contains_server(data: &Data, server_id: u64) -> bool {
|
||||||
let dc_data_lock = data.discord_data.lock().await;
|
let dc_data_lock = data.discord_data.lock().await;
|
||||||
let dc_data = dc_data_lock.as_ref().unwrap();
|
let dc_data = dc_data_lock.as_ref().unwrap();
|
||||||
|
|||||||
@@ -1,16 +1,6 @@
|
|||||||
use crate::{data::dc_add_server, lang, messages::send_msg, Context, Error};
|
use crate::{data::dc_add_server, lang, messages::send_msg, Context, Error};
|
||||||
|
|
||||||
|
|
||||||
#[poise::command(
|
|
||||||
slash_command,
|
|
||||||
prefix_command,
|
|
||||||
rename = "add_server",
|
|
||||||
category = "db",
|
|
||||||
default_member_permissions = "ADMINISTRATOR",
|
|
||||||
guild_only,
|
|
||||||
required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL"
|
|
||||||
)]
|
|
||||||
/// Add your server to my database so I can sell it! (/s), I only store some minimal data the bot needs.
|
|
||||||
pub async fn cmd(
|
pub async fn cmd(
|
||||||
ctx: Context<'_>
|
ctx: Context<'_>
|
||||||
) -> Result<(), Error>
|
) -> Result<(), Error>
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
use crate::{Context, Error, db_cmds::{add_server, reddit_channel, wwrps_channel}};
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(poise::ChoiceParameter, PartialEq)]
|
||||||
|
pub enum Subcommands {
|
||||||
|
AddServer,
|
||||||
|
RedditChannel,
|
||||||
|
WWRPSChannel
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[poise::command(
|
||||||
|
slash_command,
|
||||||
|
prefix_command,
|
||||||
|
category = "db",
|
||||||
|
rename = "database",
|
||||||
|
owners_only,
|
||||||
|
default_member_permissions = "ADMINISTRATOR",
|
||||||
|
required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL"
|
||||||
|
)]
|
||||||
|
/// Various debug utilities
|
||||||
|
pub async fn cmd(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Subcommand"] subcommand: Subcommands,
|
||||||
|
) -> Result<(), Error>
|
||||||
|
{
|
||||||
|
match subcommand {
|
||||||
|
Subcommands::AddServer => add_server::cmd(ctx).await?,
|
||||||
|
Subcommands::RedditChannel => reddit_channel::cmd(ctx).await?,
|
||||||
|
Subcommands::WWRPSChannel => wwrps_channel::cmd(ctx).await?,
|
||||||
|
//_ => return Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
@@ -1,15 +1,5 @@
|
|||||||
use crate::{data::dc_bind_bk, lang, messages::send_msg, Context, Error};
|
use crate::{data::dc_bind_bk, lang, messages::send_msg, Context, Error};
|
||||||
|
|
||||||
#[poise::command(
|
|
||||||
slash_command,
|
|
||||||
prefix_command,
|
|
||||||
rename = "admin_re_bindchannel",
|
|
||||||
category = "db",
|
|
||||||
default_member_permissions = "ADMINISTRATOR",
|
|
||||||
guild_only,
|
|
||||||
required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL"
|
|
||||||
)]
|
|
||||||
/// Sets the channel where the bot will dump all Reddit data upon using /re_updateDiscord.
|
|
||||||
pub async fn cmd(
|
pub async fn cmd(
|
||||||
ctx: Context<'_>
|
ctx: Context<'_>
|
||||||
) -> Result<(), Error>
|
) -> Result<(), Error>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
use crate::{Context, Error, data::bind_wwrps, lang, messages::send_msg};
|
||||||
|
|
||||||
|
pub async fn cmd(
|
||||||
|
ctx: Context<'_>
|
||||||
|
) -> Result<(), Error>
|
||||||
|
{
|
||||||
|
let c_id = ctx.channel_id().into();
|
||||||
|
let r = bind_wwrps(ctx.data(), ctx.guild_id().unwrap().into(), c_id).await;
|
||||||
|
|
||||||
|
if r.is_ok() {
|
||||||
|
send_msg(ctx, lang!("dc_msg_bound_channel", c_id), true, true).await;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
send_msg(ctx, lang!("dc_msg_data_server_404"), true, true).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
+6
-3
@@ -3,10 +3,12 @@ use std::{collections::HashSet, process};
|
|||||||
use poise::serenity_prelude::{ActivityData, UserId};
|
use poise::serenity_prelude::{ActivityData, UserId};
|
||||||
use poise::serenity_prelude as serenity;
|
use poise::serenity_prelude as serenity;
|
||||||
use poise::serenity_prelude::Client;
|
use poise::serenity_prelude::Client;
|
||||||
|
use tokio::sync::Mutex;
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
|
use crate::cmds::wwrps::RPSGame;
|
||||||
use crate::data::get_toml_mutex;
|
use crate::data::get_toml_mutex;
|
||||||
use crate::{Args, Cmd, Data, cmds, data, debug_cmds, events, re_cmds, rs_println};
|
use crate::{Args, Cmd, Data, cmds, data, db_cmds, debug_cmds, events, re_cmds, rs_println};
|
||||||
|
|
||||||
|
|
||||||
pub async fn gen_data(args: Args, owners: Vec<u64>) -> Data {
|
pub async fn gen_data(args: Args, owners: Vec<u64>) -> Data {
|
||||||
@@ -26,6 +28,7 @@ pub async fn gen_data(args: Args, owners: Vec<u64>) -> Data {
|
|||||||
let data = Data {
|
let data = Data {
|
||||||
owners,
|
owners,
|
||||||
ball_prompts: [ball_classic, ball_quirk],
|
ball_prompts: [ball_classic, ball_quirk],
|
||||||
|
rps_game: Mutex::new(RPSGame::new()),
|
||||||
bk_mods: mods_vec_u64,
|
bk_mods: mods_vec_u64,
|
||||||
reddit_data: None.into(),
|
reddit_data: None.into(),
|
||||||
discord_data: None.into(),
|
discord_data: None.into(),
|
||||||
@@ -86,6 +89,7 @@ async fn make_cmd_vec(data: &Data) -> Vec<Cmd> {
|
|||||||
// GENERIC
|
// GENERIC
|
||||||
cmds::help::cmd(),
|
cmds::help::cmd(),
|
||||||
cmds::eight_ball::cmd(),
|
cmds::eight_ball::cmd(),
|
||||||
|
cmds::wwrps::cmd(),
|
||||||
// REDDIT
|
// REDDIT
|
||||||
re_cmds::add::cmd(),
|
re_cmds::add::cmd(),
|
||||||
re_cmds::approve::cmd(),
|
re_cmds::approve::cmd(),
|
||||||
@@ -100,8 +104,7 @@ async fn make_cmd_vec(data: &Data) -> Vec<Cmd> {
|
|||||||
cmds::send::cmd(),
|
cmds::send::cmd(),
|
||||||
debug_cmds::main_cmd::cmd(),
|
debug_cmds::main_cmd::cmd(),
|
||||||
// DATABASE
|
// DATABASE
|
||||||
re_cmds::admin_bind::cmd(),
|
db_cmds::main_cmd::cmd()
|
||||||
cmds::add_server::cmd(),
|
|
||||||
];
|
];
|
||||||
let cfg = get_toml_mutex(&data.cfg).await.unwrap();
|
let cfg = get_toml_mutex(&data.cfg).await.unwrap();
|
||||||
|
|
||||||
|
|||||||
+9
-2
@@ -3,15 +3,14 @@
|
|||||||
#![allow(static_mut_refs)]
|
#![allow(static_mut_refs)]
|
||||||
|
|
||||||
mod cmds {
|
mod cmds {
|
||||||
pub mod add_server;
|
|
||||||
pub mod eight_ball;
|
pub mod eight_ball;
|
||||||
pub mod embed;
|
pub mod embed;
|
||||||
pub mod help;
|
pub mod help;
|
||||||
pub mod send;
|
pub mod send;
|
||||||
|
pub mod wwrps;
|
||||||
}
|
}
|
||||||
mod re_cmds {
|
mod re_cmds {
|
||||||
pub mod add;
|
pub mod add;
|
||||||
pub mod admin_bind;
|
|
||||||
pub mod approve;
|
pub mod approve;
|
||||||
pub mod generic_fns;
|
pub mod generic_fns;
|
||||||
pub mod get;
|
pub mod get;
|
||||||
@@ -31,6 +30,12 @@ mod debug_cmds {
|
|||||||
pub mod view_guilds;
|
pub mod view_guilds;
|
||||||
pub mod whoami;
|
pub mod whoami;
|
||||||
}
|
}
|
||||||
|
mod db_cmds {
|
||||||
|
pub mod add_server;
|
||||||
|
pub mod reddit_channel;
|
||||||
|
pub mod main_cmd;
|
||||||
|
pub mod wwrps_channel;
|
||||||
|
}
|
||||||
mod events;
|
mod events;
|
||||||
mod messages;
|
mod messages;
|
||||||
mod python;
|
mod python;
|
||||||
@@ -58,6 +63,7 @@ use tokio::runtime::Runtime;
|
|||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use websocket::send_cmd_json;
|
use websocket::send_cmd_json;
|
||||||
|
|
||||||
|
use crate::cmds::wwrps::RPSGame;
|
||||||
use crate::data::get_toml_mutex;
|
use crate::data::get_toml_mutex;
|
||||||
use crate::schedule::Schedule;
|
use crate::schedule::Schedule;
|
||||||
|
|
||||||
@@ -91,6 +97,7 @@ type Cmd = Command<Data, Box<dyn StdErr + Send + Sync>>;
|
|||||||
struct Data {
|
struct Data {
|
||||||
owners: Vec<u64>,
|
owners: Vec<u64>,
|
||||||
ball_prompts: [Vec<String>; 2],
|
ball_prompts: [Vec<String>; 2],
|
||||||
|
rps_game: Mutex<RPSGame>,
|
||||||
reddit_data: Mutex<Option<Value>>,
|
reddit_data: Mutex<Option<Value>>,
|
||||||
discord_data: Mutex<Option<Value>>,
|
discord_data: Mutex<Option<Value>>,
|
||||||
cfg: Mutex<Option<toml::Value>>,
|
cfg: Mutex<Option<toml::Value>>,
|
||||||
|
|||||||
Reference in New Issue
Block a user