示例#1
0
        public async Task RKill(CommandContext ctx)
        {
            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss] ", CultureInfo.CreateSpecificCulture("en-GB")) + "RKill Command");

            string        args;
            string        author = ctx.Member.DisplayName;
            List <string> listU  = Useful.GetOnlineNames(ctx.Channel.Guild);

            try
            {
                args = ctx.Message.Content.Split(new char[] { ' ' }, 2)[1];
            }
            catch (IndexOutOfRangeException)
            {
                args = string.Empty;
            }

            KillUser.KillResult result = KillUser.KillRandom(args, author, listU);

            switch (result.IsAction)
            {
            case true:
                await ctx.RespondAsync("*" + result.Result.Trim() + "*").ConfigureAwait(false);

                break;

            case false:
                await ctx.RespondAsync(result.Result).ConfigureAwait(false);

                break;
            }
        }
示例#2
0
        public async Task Poke(CommandContext ctx, params string[] names)
        {
            logger.Info("Poke Command", Useful.GetDiscordName(ctx));

            string result = Basics.PokeRandom(Useful.GetOnlineNames(ctx.Channel.Guild), Useful.GetUsername(ctx));
            await ctx.RespondAsync(result).ConfigureAwait(false);
        }
示例#3
0
        public async Task Fact(CommandContext ctx, [RemainingText] string args)
        {
            logger.Info("Fact Command", Useful.GetDiscordName(ctx));

            string result = Commands.Fact.ShowFact(args, Useful.GetOnlineNames(ctx.Channel.Guild), Useful.GetUsername(ctx));

            await ctx.Message.RespondAsync(result).ConfigureAwait(false);
        }
示例#4
0
        public async Task Poke(CommandContext ctx)
        {
            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss] ", CultureInfo.CreateSpecificCulture("en-GB")) + "Poke Command");

            List <string> listU = Useful.GetOnlineNames(ctx.Channel.Guild);
            string        user  = ctx.Member.DisplayName;

            string result = Basics.PokeRandom(listU, user);
            await ctx.RespondAsync(result).ConfigureAwait(false);
        }
示例#5
0
        public async Task Kill(CommandContext ctx, [RemainingText] string arg)
        {
            logger.Info("Kill Command", Useful.GetDiscordName(ctx));

            KillUser.KillResult result = KillUser.Kill(Useful.GetUsername(ctx), Useful.GetOnlineNames(ctx.Channel.Guild), arg);

            switch (result.IsAction)
            {
            case true:
                await ctx.RespondAsync("*" + result.Result + "*").ConfigureAwait(false);

                break;

            case false:
                await ctx.RespondAsync(result.Result).ConfigureAwait(false);

                break;
            }
        }
示例#6
0
        public async Task Fact(CommandContext ctx)
        {
            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss] ", CultureInfo.CreateSpecificCulture("en-GB")) + "Fact Command");

            List <string> listU = Useful.GetOnlineNames(ctx.Channel.Guild);
            string        user  = ctx.Member.DisplayName;
            string        args;

            try
            {
                args = ctx.Message.Content.Split(new char[] { ' ' }, 2)[1];
            }
            catch (IndexOutOfRangeException)
            {
                args = string.Empty;
            }

            string result = Commands.Fact.ShowFact(args, listU, user);

            await ctx.Message.RespondAsync(result).ConfigureAwait(false);
        }
示例#7
0
        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);
        }
示例#8
0
        public async Task RandomKill(CommandContext ctx)
        {
            logger.Info("rkill Command", Useful.GetDiscordName(ctx));

            KillUser.KillResult result = KillUser.KillRandom(Useful.GetUsername(ctx), Useful.GetOnlineNames(ctx.Channel.Guild));

            switch (result.IsAction)
            {
            case true:
                await ctx.RespondAsync("*" + result.Result.Trim() + "*").ConfigureAwait(false);

                break;

            case false:
                await ctx.RespondAsync(result.Result).ConfigureAwait(false);

                break;
            }
        }