mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
refactor: start to stop using ctx.Match
This commit is contained in:
parent
b89bc44a27
commit
e70d69e45c
6 changed files with 56 additions and 35 deletions
|
|
@ -6,6 +6,19 @@ public partial class CommandTree
|
|||
{
|
||||
public Task ExecuteCommand(Context ctx)
|
||||
{
|
||||
switch (ctx.Parameters.Callback())
|
||||
{
|
||||
case "fun_thunder":
|
||||
return ctx.Execute<Fun>(null, m => m.Thunder(ctx));
|
||||
default:
|
||||
// don't send an "invalid command" response if the guild has those turned off
|
||||
if (ctx.GuildConfig != null && ctx.GuildConfig!.InvalidCommandResponseEnabled != true)
|
||||
return Task.CompletedTask;
|
||||
|
||||
// remove compiler warning
|
||||
return ctx.Reply(
|
||||
$"{Emojis.Error} Unknown command {ctx.PeekArgument().AsCode()}. For a list of possible commands, see <https://pluralkit.me/commands>.");
|
||||
}
|
||||
if (ctx.Match("system", "s"))
|
||||
return HandleSystemCommand(ctx);
|
||||
if (ctx.Match("member", "m"))
|
||||
|
|
@ -107,14 +120,6 @@ public partial class CommandTree
|
|||
return ctx.Execute<Random>(MemberRandom, m => m.Member(ctx, ctx.System));
|
||||
if (ctx.Match("dashboard", "dash"))
|
||||
return ctx.Execute<Help>(Dashboard, m => m.Dashboard(ctx));
|
||||
|
||||
// don't send an "invalid command" response if the guild has those turned off
|
||||
if (ctx.GuildConfig != null && ctx.GuildConfig!.InvalidCommandResponseEnabled != true)
|
||||
return Task.CompletedTask;
|
||||
|
||||
// remove compiler warning
|
||||
return ctx.Reply(
|
||||
$"{Emojis.Error} Unknown command {ctx.PeekArgument().AsCode()}. For a list of possible commands, see <https://pluralkit.me/commands>.");
|
||||
}
|
||||
|
||||
private async Task HandleAdminAbuseLogCommand(Context ctx)
|
||||
|
|
|
|||
|
|
@ -29,6 +29,11 @@ public class ParametersFFI
|
|||
}
|
||||
}
|
||||
|
||||
public string Callback()
|
||||
{
|
||||
return _cb;
|
||||
}
|
||||
|
||||
public string Pop()
|
||||
{
|
||||
if (_args.Count > _ptr + 1) Console.WriteLine($"pop: {_ptr + 1}, {_args[_ptr + 1]}");
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use smol_str::SmolStr;
|
|||
|
||||
use crate::{command, token::Token};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Command {
|
||||
// TODO: fix hygiene
|
||||
pub tokens: Vec<Token>,
|
||||
|
|
|
|||
|
|
@ -1 +1,10 @@
|
|||
use super::*;
|
||||
|
||||
pub fn cmds() -> impl Iterator<Item = Command> {
|
||||
[command!(
|
||||
[Token::cmd("thunder")],
|
||||
"fun_thunder",
|
||||
"Shows the help command"
|
||||
)]
|
||||
.into_iter()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![feature(let_chains)]
|
||||
|
||||
mod commands;
|
||||
pub mod commands;
|
||||
mod string;
|
||||
mod token;
|
||||
mod tree;
|
||||
|
|
@ -17,7 +17,7 @@ pub use commands::Command;
|
|||
pub use token::*;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref COMMAND_TREE: TreeBranch = {
|
||||
pub static ref COMMAND_TREE: TreeBranch = {
|
||||
let mut tree = TreeBranch {
|
||||
current_command_key: None,
|
||||
possible_tokens: vec![],
|
||||
|
|
|
|||
50
flake.nix
50
flake.nix
|
|
@ -43,22 +43,6 @@
|
|||
...
|
||||
}:
|
||||
let
|
||||
# this is used as devshell for bot, and in the process-compose processes as environment
|
||||
mkBotEnv =
|
||||
cmd:
|
||||
pkgs.buildFHSEnv {
|
||||
name = "env";
|
||||
targetPkgs =
|
||||
pkgs: with pkgs; [
|
||||
coreutils
|
||||
git
|
||||
dotnet-sdk_8
|
||||
gcc
|
||||
omnisharp-roslyn
|
||||
bashInteractive
|
||||
];
|
||||
runScript = cmd;
|
||||
};
|
||||
uniffi-bindgen-cs = config.nci.lib.buildCrate {
|
||||
src = inp.uniffi-bindgen-cs;
|
||||
cratePath = "bindgen";
|
||||
|
|
@ -75,7 +59,7 @@
|
|||
programs.nixfmt.enable = true;
|
||||
};
|
||||
|
||||
nci.projects."pluralkit-services" = {
|
||||
nci.projects."pk-services" = {
|
||||
path = ./.;
|
||||
export = false;
|
||||
};
|
||||
|
|
@ -118,9 +102,23 @@
|
|||
packages = lib.genAttrs [ "gateway" "commands" ] (name: rustOutputs.${name}.packages.release);
|
||||
# TODO: package the bot itself (dotnet)
|
||||
|
||||
devShells = {
|
||||
services = rustOutputs."pluralkit-services".devShell;
|
||||
bot = (mkBotEnv "bash").env;
|
||||
devShells = rec {
|
||||
services = rustOutputs."pk-services".devShell;
|
||||
bot = pkgs.mkShell {
|
||||
name = "pkbot-devshell";
|
||||
nativeBuildInputs = with pkgs; [
|
||||
coreutils
|
||||
git
|
||||
dotnet-sdk_8
|
||||
gcc
|
||||
omnisharp-roslyn
|
||||
bashInteractive
|
||||
];
|
||||
};
|
||||
all = (pkgs.mkShell.override { stdenv = services.stdenv; }) {
|
||||
name = "pk-devshell";
|
||||
nativeBuildInputs = bot.nativeBuildInputs ++ services.nativeBuildInputs;
|
||||
};
|
||||
};
|
||||
|
||||
process-compose."dev" =
|
||||
|
|
@ -194,27 +192,31 @@
|
|||
pluralkit-bot-init = {
|
||||
command = pkgs.writeShellApplication {
|
||||
name = "pluralkit-bot-init";
|
||||
runtimeInputs = [
|
||||
runtimeInputs = self'.devShells.bot.nativeBuildInputs ++ [
|
||||
pkgs.coreutils
|
||||
pkgs.git
|
||||
self'.devShells.bot.stdenv.cc
|
||||
];
|
||||
text = ''
|
||||
${sourceDotenv}
|
||||
set -x
|
||||
${pluralkitConfCheck}
|
||||
${self'.apps.generate-command-parser-bindings.program}
|
||||
exec ${mkBotEnv "dotnet build -c Release -o obj/"}/bin/env
|
||||
exec dotnet build -c Release -o obj/
|
||||
'';
|
||||
};
|
||||
};
|
||||
pluralkit-bot = {
|
||||
command = pkgs.writeShellApplication {
|
||||
name = "pluralkit-bot";
|
||||
runtimeInputs = [ pkgs.coreutils ];
|
||||
runtimeInputs = self'.devShells.bot.nativeBuildInputs ++ [
|
||||
pkgs.coreutils
|
||||
self'.devShells.bot.stdenv.cc
|
||||
];
|
||||
text = ''
|
||||
${sourceDotenv}
|
||||
set -x
|
||||
exec ${mkBotEnv "dotnet obj/PluralKit.Bot.dll"}/bin/env
|
||||
exec dotnet obj/PluralKit.Bot.dll
|
||||
'';
|
||||
};
|
||||
depends_on.pluralkit-bot-init.condition = "process_completed_successfully";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue