public async Task RemoveCustomCommand(CommandContext ctx) { Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss] ", CultureInfo.CreateSpecificCulture("en-GB")) + "removecmd Command"); string[] splits; splits = ctx.Message.Content.Split(new char[] { ' ' }, 3); if (Useful.MemberIsBotOperator(ctx.Member) || ctx.Member.IsOwner) { CustomCommand.RemoveCommandByName(splits[1], CustomCommand.CustomCommands); CustomCommand.SaveCustomCommands(CustomCommand.CustomCommands); string message = "Command " + splits[1] + " removed."; await ctx.RespondAsync(message).ConfigureAwait(false); } }
public async Task RemoveCustomCommand(CommandContext ctx, string commandName) { logger.Info("removecmd Command", Useful.GetDiscordName(ctx)); if (Useful.MemberIsBotOperator(ctx.Member) || ctx.Member.IsOwner) { if (CustomCommand.RemoveCommandByName(commandName)) { CustomCommand.SaveCustomCommands(); await ctx.RespondAsync("Command " + commandName + " removed.").ConfigureAwait(false); } else { await ctx.RespondAsync("Command " + commandName + " not found.").ConfigureAwait(false); } } }
private static async Task MainAsync(string[] args) { string token = args[0]; bool quit = false; bool tryReconnect = false; string botName = string.Empty; //TODO: This should be fixed once .net Core 3.0 is released /*if (Settings.Default.UpgradeNeeded) * { * Settings.Default.Upgrade(); * Settings.Default.UpgradeNeeded = false; * Settings.Default.Save(); * }*/ Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss] ", CultureInfo.CreateSpecificCulture("en-GB")) + "Starting..."); if (string.IsNullOrWhiteSpace(Settings.Default.apikey)) { string api = string.Empty; if (args.Length > 1) { api = args[1]; } else { Console.WriteLine("Add api key for youtube search (or enter to ignore): "); api = Console.ReadLine(); } if (!string.IsNullOrWhiteSpace(api)) { Settings.Default.apikey = api; //TODO: This should be fixed once .net Core 3.0 is released //Settings.Default.Save(); } } if (string.IsNullOrWhiteSpace(Settings.Default.CleverbotAPI)) { string api = string.Empty; if (args.Length > 2) { api = args[2]; } else { Console.WriteLine("Add api key for Cleverbot (or enter to ignore): "); api = Console.ReadLine(); } if (!string.IsNullOrWhiteSpace(api)) { Settings.Default.CleverbotAPI = api; //TODO: This should be fixed once .net Core 3.0 is released //Settings.Default.Save(); } } GetDiscordClient = new DiscordClient(new DiscordConfiguration { Token = token, TokenType = TokenType.Bot }); GetDiscordClient.SocketErrored += async a => { tryReconnect = true; await Console.Out.WriteLineAsync(DateTime.Now.ToString("[HH:mm:ss] ", CultureInfo.CreateSpecificCulture("en-GB")) + "Error: " + a.Exception.Message).ConfigureAwait(false); }; GetDiscordClient.Ready += async a => { await Console.Out.WriteLineAsync(DateTime.Now.ToString("[HH:mm:ss] ", CultureInfo.CreateSpecificCulture("en-GB")) + "Ready!").ConfigureAwait(false); tryReconnect = false; }; GetDiscordClient.UnknownEvent += async unk => { await Console.Out.WriteLineAsync(DateTime.Now.ToString("[HH:mm:ss] ", CultureInfo.CreateSpecificCulture("en-GB")) + "Unknown Event: " + unk.EventName).ConfigureAwait(false); }; GetDiscordClient.MessageCreated += async e => { if (e.Message.Content.StartsWith("!quit", StringComparison.OrdinalIgnoreCase)) { DiscordMember author = await e.Guild.GetMemberAsync(e.Author.Id).ConfigureAwait(false); bool isBotAdmin = Useful.MemberIsBotOperator(author); if (author.IsOwner || isBotAdmin) { quit = true; Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss] ", CultureInfo.CreateSpecificCulture("en-GB")) + "Quitting..."); } } //CustomCommands else if (e.Message.Content.StartsWith('!')) { string arguments = string.Empty; string[] split = e.Message.Content.Split(new char[] { ' ' }, 2); string command = split[0]; if (split.Length > 1) { arguments = split[1]; } string nick = ((DiscordMember)e.Message.Author).DisplayName; List <string> listU = Useful.GetOnlineNames(e.Channel.Guild); string result = CustomCommand.UseCustomCommand(command.TrimStart('!'), arguments, nick, listU); if (!string.IsNullOrEmpty(result)) { await e.Message.RespondAsync(result).ConfigureAwait(false); } } //Bot Talk and Cleverbot else if (e.Message.Content.StartsWith(botName + ",", StringComparison.OrdinalIgnoreCase)) { if (e.Message.Content.EndsWith('?')) { } else { await Think(e, botName).ConfigureAwait(false); } } else if (e.Message.Content.EndsWith(botName, StringComparison.OrdinalIgnoreCase)) { await Think(e, botName).ConfigureAwait(false); } //waifunator if (!string.IsNullOrWhiteSpace(e.Message.Content) && e.Message.Author.Id == Settings.Default.limid) //lims shitty id lul { if (e.Message.Content.Contains("wife", StringComparison.OrdinalIgnoreCase)) { await e.Message.CreateReactionAsync(DiscordEmoji.FromName(GetDiscordClient, ":regional_indicator_w:")).ConfigureAwait(false); await e.Message.CreateReactionAsync(DiscordEmoji.FromName(GetDiscordClient, ":regional_indicator_a:")).ConfigureAwait(false); await e.Message.CreateReactionAsync(DiscordEmoji.FromName(GetDiscordClient, ":regional_indicator_i:")).ConfigureAwait(false); await e.Message.CreateReactionAsync(DiscordEmoji.FromName(GetDiscordClient, ":regional_indicator_f:")).ConfigureAwait(false); await e.Message.CreateReactionAsync(DiscordEmoji.FromName(GetDiscordClient, ":regional_indicator_u:")).ConfigureAwait(false); } } //Update "last seen" for user that sent the message string username = ((DiscordMember)e.Message.Author).DisplayName.ToLower(CultureInfo.CreateSpecificCulture("en-GB")); Seen.MarkUserSeen(username); Seen.SaveSeen(Seen.SeenTime); //Ping users, leave this last cause it's sloooooooow await PingUser.SendPings(e).ConfigureAwait(false); }; //Register the commands defined on SekiCommands.cs commands = GetDiscordClient.UseCommandsNext(new CommandsNextConfiguration { StringPrefix = "!", CaseSensitive = false, EnableMentionPrefix = false }); commands.RegisterCommands <SekiCommands>(); //Connect to Discord await GetDiscordClient.ConnectAsync().ConfigureAwait(false); botName = GetDiscordClient.CurrentUser.Username; while (!quit) { if (tryReconnect) { try { await GetDiscordClient.DisconnectAsync().ConfigureAwait(false); } finally { Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss] ", CultureInfo.CreateSpecificCulture("en-GB")) + "Attempting to Reconnect..."); await GetDiscordClient.ConnectAsync().ConfigureAwait(false); } } //Wait a bit await Task.Delay(10 * 1000).ConfigureAwait(false); } await GetDiscordClient.DisconnectAsync().ConfigureAwait(false); }