private async Task Client_JoinedGuild(IGuild arg) { Locale locale = Locale.GetEntity(arg.Id.ToDbLong()); ITextChannel defaultChannel = await arg.GetDefaultChannelAsync(); await defaultChannel.SendMessage(locale.GetString("miki_join_message")); // if miki patreon is present, leave again. DogStatsd.Increment("guilds.joined"); DogStatsd.Counter("guilds", Bot.instance.Client.Guilds.Count); }
private async Task Client_JoinedGuild(IGuild arg) { ITextChannel defaultChannel = await arg.GetDefaultChannelAsync(); await defaultChannel.SendMessage("Hello, I am **Miki**! At your service!\nTry to use **>help** to check out what i can do! :notes:"); }
void IService.Install(DiscordClient client) { Client = client; if (Config.HelpMode != HelpMode.Disabled) { CreateCommand("help") .Parameter("command", ParameterType.Multiple) .Hide() .Description("Returns information about commands.") .Do(async e => { ITextChannel replyChannel = Config.HelpMode == HelpMode.Public ? e.Channel : await e.User.CreatePMChannel().ConfigureAwait(false); if (e.Args.Length > 0) //Show command help { var map = _map.GetItem(string.Join(" ", e.Args)); if (map != null) { await ShowCommandHelp(map, e.User, e.Channel, replyChannel).ConfigureAwait(false); } else { await replyChannel.SendMessage("Unable to display help: Unknown command.").ConfigureAwait(false); } } else //Show general help { await ShowGeneralHelp(e.User, e.Channel, replyChannel).ConfigureAwait(false); } }); } client.MessageReceived += async(s, e) => { if (_allCommands.Count == 0) { return; } if (e.Message.User == null || e.Message.User.Id == Client.CurrentUser.Id) { return; } string msg = e.Message.RawText; if (msg.Length == 0) { return; } string cmdMsg = null; //Check for command char if (Config.PrefixChar.HasValue) { if (msg[0] == Config.PrefixChar.Value) { cmdMsg = msg.Substring(1); } } //Check for mention if (cmdMsg == null && Config.AllowMentionPrefix) { string mention = client.CurrentUser.Mention; if (msg.StartsWith(mention) && msg.Length > mention.Length) { cmdMsg = msg.Substring(mention.Length + 1); } else { mention = $"@{client.CurrentUser.Name}"; if (msg.StartsWith(mention) && msg.Length > mention.Length) { cmdMsg = msg.Substring(mention.Length + 1); } } } //Check using custom activator if (cmdMsg == null && Config.CustomPrefixHandler != null) { int index = Config.CustomPrefixHandler(e.Message); if (index >= 0) { cmdMsg = msg.Substring(index); } } if (cmdMsg == null) { return; } //Parse command IEnumerable <Command> commands; int argPos; CommandParser.ParseCommand(cmdMsg, _map, out commands, out argPos); if (commands == null) { CommandEventArgs errorArgs = new CommandEventArgs(e.Message, null, null); OnCommandError(CommandErrorType.UnknownCommand, errorArgs); return; } else { foreach (var command in commands) { //Parse arguments string[] args; var error = CommandParser.ParseArgs(cmdMsg, argPos, command, out args); if (error != null) { if (error == CommandErrorType.BadArgCount) { continue; } else { var errorArgs = new CommandEventArgs(e.Message, command, null); OnCommandError(error.Value, errorArgs); return; } } var eventArgs = new CommandEventArgs(e.Message, command, args); // Check permissions string errorText; if (!command.CanRun(eventArgs.User, eventArgs.Channel, out errorText)) { OnCommandError(CommandErrorType.BadPermissions, eventArgs, errorText != null ? new Exception(errorText) : null); return; } // Run the command try { OnCommand(eventArgs); await command.Run(eventArgs).ConfigureAwait(false); } catch (Exception ex) { OnCommandError(CommandErrorType.Exception, eventArgs, ex); } return; } var errorArgs2 = new CommandEventArgs(e.Message, null, null); OnCommandError(CommandErrorType.BadArgCount, errorArgs2); } }; }