Exemplo n.º 1
0
 public void OverwriteGuildSettings(GuildSettings old, GuildSettings _new)
 {
     Program.Rin.guildSettings.Remove(old);
     Program.Rin.guildSettings.Add(_new);
     session.Delete <GuildSettings>(old);
     session.Store(_new);
     session.SaveChanges();
 }
Exemplo n.º 2
0
        public async Task OnJoinGuildAsync(SocketGuild guild)
        {
            await guild.DefaultChannel.TriggerTypingAsync();

            await guild.DefaultChannel.SendMessageAsync("Hi there, I'm Rin Bot! \n I'm still in development, so dont count on me all the time.");

            var settings = new GuildSettings(guild);

            guildSettings.Add(settings);
            dbManager.SaveGuildSettings(settings);
        }
Exemplo n.º 3
0
        public async Task HandleCommandAsync(SocketMessage msg)
        {
            var message = msg as SocketUserMessage;

            if (message is null || message.Author.IsBot)
            {
                return;
            }

            int argPos  = 0;
            var context = new SocketCommandContext(client, message);

            GuildSettings activeGuildSettings = guildSettings.Find(s => s.guildID == context.Guild.Id);

            if (activeGuildSettings == null)
            {
                activeGuildSettings = new GuildSettings(context);
                dbManager.SaveGuildSettings(activeGuildSettings);
                guildSettings.Add(activeGuildSettings);
            }

            if (message.HasStringPrefix("rin!", ref argPos))
            {
                var result = await commands.ExecuteAsync(context, argPos, services);

                if (!result.IsSuccess)
                {
                    Console.WriteLine(result.ErrorReason);
                }
                if (result.Error == CommandError.UnknownCommand)
                {
                    await message.Channel.SendMessageAsync("I can't do that! (yet?) Use rin!help if you're unsure!");
                }
                return;
            }
            if (activeGuildSettings.settings[Setting.RinPing] && message.Content.Contains("<@454391745044676608>"))  //activeGuildSettings.settings[Setting.RinPing]
            {
                Random r = new Random();
                var    i = r.Next(0, pingTexts.Length);
                await message.Channel.SendMessageAsync(pingTexts[i]);

                return;
            }
            if (activeGuildSettings.settings[Setting.AllowAtSomeone] && message.Content.Contains("@someone"))  //activeGuildSettings.settings[Setting.AllowAtSomeone]
            {
                var possible = context.Guild.Users.Where(x => x.Id != client.CurrentUser.Id && x != message.Author);
                var target   = possible.ElementAt(random.Next(0, possible.Count()));
                //await message.Channel.SendMessageAsync($"{target.Mention} {text}");
                var text = message.Content.Replace("@someone", $"{target.Mention}");
                await message.Channel.SendMessageAsync($"{text} - by {message.Author.Username}, using @someone");

                await message.DeleteAsync();
            }
        }
Exemplo n.º 4
0
        public async Task NoLogAsync()
        {
            var settings = DBManager.GetGuildSettings(Context.Guild.Id);

            if (settings == null)
            {
                settings = new GuildSettings(Context.Guild);
            }
            settings.logChannelID = 0;
            DBManager.SaveGuildSettings(settings);
            await ReplyAsync("Log Channel disabled.");
        }
Exemplo n.º 5
0
        public async Task SetLogAsync([Remainder] IChannel channel)
        {
            var settings = DBManager.GetGuildSettings(Context.Guild.Id);

            if (settings == null)
            {
                settings = new GuildSettings(Context.Guild);
            }
            settings.logChannelID = channel.Id;
            DBManager.SaveGuildSettings(settings);
            await ReplyAsync($"Log Channel set to: #{channel.Name}");
        }
Exemplo n.º 6
0
        public async Task ToggleSettingAsync([Remainder] string setting)
        {
            var     session = DBManager.session;
            Setting targetSetting;
            string  targetString;

            if (Enum.TryParse <Setting>(setting, true, out targetSetting))
            {
                targetString = targetSetting.ToString();
                var guildSettings = DBManager.GetGuildSettings(Context.Guild.Id);
                if (guildSettings == null)
                {
                    //Change the targeted Value.
                    guildSettings = new GuildSettings(Context);

                    var settingValue = guildSettings.settings[targetSetting];
                    guildSettings.settings[targetSetting] = !settingValue;
                    await ReplyAsync($"Setting {targetString}` has been set to `{!settingValue}`.");

                    DBManager.SaveGuildSettings(guildSettings);
                    Rin.guildSettings.Add(guildSettings);
                }
                else
                {
                    bool settingValue;
                    //Get current value, then change it and insert back into DB
                    //if the value exists, do this:
                    if (guildSettings.settings.TryGetValue(targetSetting, out settingValue))
                    {
                        guildSettings.settings[targetSetting] = !settingValue;
                        await ReplyAsync($"Setting `{targetString}` has been set to `{!settingValue}`.");
                    }
                    else //if the value for the setting doesnt exist, add it!
                    {
                        guildSettings.settings.Add(targetSetting, false);
                        await ReplyAsync($"Setting `{setting}` has been initialized as `false`. (Did not exist in this Context yet.)");
                    }
                    //await ReplyAsync($"Setting {targetSetting.ToString()}` has been set to `{!settingValue}`.");
                    DBManager.SaveGuildSettings(guildSettings);
                }
            }
            else
            {
                await ReplyAsync($"Setting name {setting} does not exist.");
            }
        }
Exemplo n.º 7
0
        public async Task ShowSettingsAsync()
        {
            var session       = DBManager.session;
            var guildSettings = DBManager.GetGuildSettings(Context.Guild.Id);

            if (guildSettings == null)
            {
                guildSettings = new GuildSettings(Context);
                DBManager.SaveGuildSettings(guildSettings);
                Rin.guildSettings.Add(guildSettings);
            }

            string settingList = $"**Settings for {Context.Guild.Name}** \n";

            foreach (KeyValuePair <Setting, bool> entry in guildSettings.settings)
            {
                settingList += $"`{entry.Key.ToString()}` : `{entry.Value.ToString()}` \n";
            }
            if (guildSettings.logChannelID != 0)
            {
                settingList += $"Log Channel: #{Context.Guild.GetChannel(guildSettings.logChannelID).Name}";
            }
            await ReplyAsync(settingList);
        }
Exemplo n.º 8
0
 public void SaveGuildSettings(GuildSettings settings)
 {
     session.Store(settings);
     session.SaveChanges();
 }