Beispiel #1
0
 public async Task SetConfig(string key, string value)
 {
     if (ConfigMan.Config.ContainsKey(key))
     {
         ConfigMan.Update(key, value);
         await Context.Channel.SendMessageAsync($"Updated {key} to {value}");
     }
 }
Beispiel #2
0
 public static string input(SocketCommandContext context, IEnumerable<IMessage> messages) 
 { 
     StringBuilder input = new StringBuilder();
     string formatter = ConfigMan.Get("messageFormat");
     foreach (var message in messages.ToArray().Reverse())
     {
         if(!string.IsNullOrEmpty(formatter))
             input.Append((formatter + "\r\n").Replace("[author]", message.Author.Username).Replace("[content]", message.Content);
Beispiel #3
0
        public async Task Config()
        {
            StringBuilder bob = new StringBuilder();

            bob.Append($"Generating text from last {ConfigMan.Get("numMessages")} messages (numMessages)\r\n");
            bob.Append($"1/{ConfigMan.Get("respChance")} chance of responding (respChance)\r\n");
            bob.Append($"Conversation weighted by {ConfigMan.Get("weightFactor")} (weightFactor)\r\n");
            await Context.Channel.SendMessageAsync(bob.ToString());
        }
Beispiel #4
0
        public async Task Debug()
        {
            string users = ConfigMan.Get("adminUsers");

            if (string.IsNullOrEmpty(users) || users.Split(",").Any(x => x.ToLower().Trim() == Context.Message.Author.Username.ToLower()))
            {
                Program.debug = !Program.debug;
                await Context.Channel.SendMessageAsync((Program.debug ? "Entering debug mode" : "Exiting debug mode"));
            }
            else
            {
                await Context.Channel.SendMessageAsync("You do not have permission to perform that action");
            }
        }
Beispiel #5
0
        private async Task HandleCommandAsync(SocketMessage messageParam)
        {
            // Don't process the command if it was a system message
            var message = messageParam as SocketUserMessage;

            if (message == null)
            {
                return;
            }

            // Create a number to track where the prefix ends and the command begins
            int argPos = 0;

            //Ignore bots
            if (message.Author.IsBot)
            {
                return;
            }

            // Create a WebSocket-based command context based on the message
            var context = new SocketCommandContext(_client, message);

            messageNum = int.Parse(ConfigMan.Get("NumMessages"));
            var messages = await context.Channel.GetMessagesAsync(context.Message, Direction.Before, int.Parse(ConfigMan.Get("NumMessages"))).FlattenAsync();

            if (message.HasCharPrefix(ConfigMan.Get("Prefix")[0], ref argPos))
            {
                if (Program.debug || Regex.IsMatch(message.Content.Trim(), @"\+debug", RegexOptions.IgnoreCase))
                {
                    // Execute the command with the command context we just
                    // created, along with the service provider for precondition checks.
                    await _commands.ExecuteAsync(
                        context : context,
                        argPos : argPos,
                        services : null);
                }
                else
                {
                    await context.Channel.SendMessageAsync("This command requires debug mode, send +debug to toggle debug mode.");
                }
            }
            else if ((BLL.ShouldRandomlySend(context, messages, _client.CurrentUser) || Program.talkative) || message.HasMentionPrefix(_client.CurrentUser, ref argPos) && !BLL.CheckIsOtherBotPrefix(message.Content[0]))
            {
                /*@ people properly*/
                await context.Channel.SendMessageAsync();
            }
        }
Beispiel #6
0
        public async Task StartAsync()
        {
            _client      = new DiscordSocketClient();
            _client.Log += Log;

            var token = ConfigMan.Get("Token");

            await _client.LoginAsync(TokenType.Bot, token);

            await _client.StartAsync();

            CommandHandler handler = new CommandHandler(_client, new Discord.Commands.CommandService());
            await handler.InstallCommandsAsync();

            // Block this task until the program is closed.
            await Task.Delay(-1);
        }
Beispiel #7
0
        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            // Build configuration
            configuration = new ConfigurationBuilder()
                            .SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName)
                            .AddJsonFile("appsettings.json", false)
                            .Build();
            ConfigMan.Build(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            return(Host.CreateDefaultBuilder(args)
                   .ConfigureLogging(
                       options => options.AddFilter <EventLogLoggerProvider>(level => level >= LogLevel.Warning))
                   .ConfigureServices((hostContext, services) =>
            {
                services.AddHostedService <Worker>()
                .Configure <EventLogSettings>(config =>
                {
                    config.LogName = "Application";
                    config.SourceName = "GPTChatBot";
                });
                // Add access to generic IConfigurationRoot
                services.AddSingleton <IConfigurationRoot>(configuration);
            }).UseWindowsService());
        }
Beispiel #8
0
        public async Task Input()
        {
            var messages = await Context.Channel.GetMessagesAsync(Context.Message, Direction.Before, int.Parse(ConfigMan.Get("NumMessages"))).FlattenAsync();

            await Context.Channel.SendMessageAsync(BLL.input(Context, messages));
        }