예제 #1
0
        public async Task AddAutoRoleAsync(ulong id, ulong roleId)
        {
            var server = await _context.Servers
                         .FindAsync(id);

            if (server == null)
            {
                _context.Add(new Server {
                    Id = id
                });
            }
            _context.Add(new AutoRole {
                RoleId = roleId, ServerId = id
            });
            await _context.SaveChangesAsync();
        }
예제 #2
0
 public async void AddWarning(ICommandContext context, IGuildUser userWarned)
 {
     using (var db = new DiscbotContext())
     {
         var warnings = db.Warnings.AsEnumerable().Where(w => w.ServerId == (long)context.Guild.Id && w.UserWarnedId == (long)userWarned.Id).FirstOrDefault();
         if (warnings != null)
         {
             warnings.NumWarnings = warnings.NumWarnings + 1;
         }
         else
         {
             db.Warnings.Add(new Warnings
             {
                 ServerId       = (long)context.Guild.Id,
                 ServerName     = context.Guild.Name,
                 UserWarnedId   = (long)userWarned.Id,
                 UserWarnedName = userWarned.Username,
                 IssuerId       = (long)context.User.Id,
                 IssuerName     = context.User.Username,
                 TimeIssued     = DateTime.Now,
                 NumWarnings    = 1
             });
         }
         await db.SaveChangesAsync();
     }
 }
예제 #3
0
 //if (Context.Channel is IDMChannel)
 //{
 //    await ReplyAsync("DM");
 //}
 //else if (Context.Channel is IGuildChannel)
 //{
 //    await ReplyAsync("Channel");
 //}
 public async Task SetGuildBotChannelAsync(ulong channelId, string channelName, ulong userId, string userName, string guildName, ulong guildId)
 {
     await Task.Run(async() =>
     {
         using (var db = new DiscbotContext())
         {
             var currentChannel = db.ChannelOutputs.FirstOrDefault(o => o.ServerId == (long)guildId);
             if (currentChannel == null)
             {
                 var createChannel = new ChannelOutput
                 {
                     ChannelId   = (long)channelId,
                     ChannelName = channelName,
                     ServerId    = (long)guildId,
                     ServerName  = guildName,
                     SetById     = (long)userId,
                     SetByName   = userName,
                     SetTime     = DateTime.Now
                 };
                 db.ChannelOutputs.Add(createChannel);
             }
             else
             {
                 currentChannel.ChannelId   = (long)channelId;
                 currentChannel.ChannelName = channelName;
                 currentChannel.ServerId    = (long)guildId;
                 currentChannel.ServerName  = guildName;
                 currentChannel.SetById     = (long)userId;
                 currentChannel.SetByName   = userName;
                 currentChannel.SetTime     = DateTime.Now;
             }
             await db.SaveChangesAsync();
         }
     });
 }
예제 #4
0
        public async Task AddWord([Remainder] string word)
        {
            var sb = new StringBuilder();

            using (var db = new DiscbotContext())
            {
                var  words     = db.WordList.AsEnumerable().Where(w => w.ServerId == (long)Context.Guild.Id).ToList();
                bool wordFound = false;
                foreach (var singleWord in words)
                {
                    if (singleWord.Word.ToLower().Contains(word.ToLower()))
                    {
                        wordFound = true;
                    }
                }
                if (wordFound)
                {
                    sb.AppendLine($"[{word}] is already in the list!");
                }
                else
                {
                    sb.AppendLine($"Adding [{word}] to the list!");
                    db.Add(new WordList
                    {
                        ServerId   = (long)Context.Guild.Id,
                        ServerName = Context.Guild.Name,
                        Word       = word,
                        SetById    = (long)Context.User.Id
                    });
                    await db.SaveChangesAsync();
                }
            }
            await _channelServices.Reply(Context, sb.ToString());
        }
예제 #5
0
        public async Task ChangeParting([Remainder] string args = null)
        {
            var           embed = new EmbedBuilder();
            StringBuilder sb    = new StringBuilder();

            if (!string.IsNullOrEmpty(args))
            {
                embed.Title = $"Parting message change for {Context.Guild.Name}";
                sb.AppendLine("New message:");
                sb.AppendLine(args);
                using (var db = new DiscbotContext())
                {
                    try
                    {
                        var guildGreetingInfo = db.ServerGreetings.AsEnumerable().Where(g => g.DiscordGuildId == (long)Context.Guild.Id).FirstOrDefault();
                        if (guildGreetingInfo != null)
                        {
                            guildGreetingInfo.PartingMessage = args.Trim();
                            guildGreetingInfo.SetById        = (long)Context.User.Id;
                            guildGreetingInfo.SetByName      = Context.User.Username;
                            guildGreetingInfo.TimeSet        = DateTime.Now;
                        }
                        else
                        {
                            db.ServerGreetings.Add(new ServerGreeting
                            {
                                DiscordGuildId = (long)Context.Guild.Id,
                                PartingMessage = args.Trim(),
                                SetById        = (long)Context.User.Id,
                                SetByName      = Context.User.Username,
                                TimeSet        = DateTime.Now
                            });
                        }
                        await db.SaveChangesAsync();
                    }
                    catch (Exception)
                    {
                        embed.Title = $"Error changing message";
                        sb.AppendLine($"{Context.User.Mention},");
                        sb.AppendLine($"I've encounted an error, please contact the owner for help.");
                    }
                }
            }
            else
            {
                embed.Title = $"Error changing message";
                sb.AppendLine($"{Context.User.Mention},");
                sb.AppendLine($"Please provided a message!");
            }
            embed.Description = sb.ToString();
            embed.WithColor(new Color(0, 255, 0));
            embed.ThumbnailUrl = Context.Guild.IconUrl;
            await _channelServices.Reply(Context, embed);
        }
예제 #6
0
 public async void ResetWarnings(Warnings warning)
 {
     using (var db = new DiscbotContext())
     {
         var currentWarning = db.Warnings.AsEnumerable().Where(w => w.Id == warning.Id).FirstOrDefault();
         if (currentWarning != null)
         {
             db.Warnings.Remove(currentWarning);
             await db.SaveChangesAsync();
         }
     }
 }
예제 #7
0
        public async Task ToggleGreetings()
        {
            var           embed = new EmbedBuilder();
            StringBuilder sb    = new StringBuilder();

            using (var db = new DiscbotContext())
            {
                try
                {
                    var currentSetting = db.ServerGreetings.AsEnumerable().Where(g => g.DiscordGuildId == (long)Context.Guild.Id).FirstOrDefault();
                    if (currentSetting != null)
                    {
                        if (currentSetting.GreetUsers == true)
                        {
                            currentSetting.GreetUsers = false;
                            sb.AppendLine("Greetings have been disabled!");
                        }
                        else
                        {
                            currentSetting.GreetUsers          = true;
                            currentSetting.GreetingChannelId   = (long)Context.Channel.Id;
                            currentSetting.GreetingChannelName = Context.Channel.Name;
                            sb.AppendLine("Greetings have been enabled!");
                        }
                    }
                    else
                    {
                        db.ServerGreetings.Add(new ServerGreeting
                        {
                            DiscordGuildId      = (long)Context.Guild.Id,
                            GreetingChannelId   = (long)Context.Channel.Id,
                            GreetingChannelName = Context.Channel.Name,
                            GreetUsers          = true
                        });
                        sb.AppendLine("Greetings have been enabled!");
                    }
                    await db.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error toggling greetings -> [{ex.Message}]!");
                }
            }
            embed.Title       = $"User greeting settings for {Context.Guild.Name}";
            embed.Description = sb.ToString();
            embed.WithColor(new Color(0, 255, 0));
            embed.ThumbnailUrl = Context.Guild.IconUrl;
            await _channelServices.Reply(Context, embed);
        }
예제 #8
0
        public async Task ModifyGuildPrefix(ulong id, string prefix)
        {
            var server = await _context.Servers
                         .FindAsync(id);

            if (server == null)
            {
                _context.Add(new Server {
                    Id = id, Prefix = prefix
                });
            }
            else
            {
                server.Prefix = prefix;
            }
            await _context.SaveChangesAsync();
        }
예제 #9
0
        public async Task <string> SetNoteInfo(ICommandContext Context, string noteText)
        {
            StringBuilder sb = new StringBuilder();

            try
            {
                using (var db = new DiscbotContext())
                {
                    var currentNote = db.Notes.FirstOrDefault(c => c.ServerId == (long)Context.Guild.Id);
                    if (currentNote == null)
                    {
                        Note n = new Note()
                        {
                            Note1      = noteText,
                            ServerId   = (long)Context.Guild.Id,
                            ServerName = Context.Guild.Name,
                            SetBy      = Context.User.Username,
                            SetById    = (long)Context.User.Id,
                            TimeSet    = DateTime.Now
                        };
                        db.Notes.Add(n);
                    }
                    else
                    {
                        currentNote.Note1   = noteText;
                        currentNote.SetBy   = Context.User.Username;
                        currentNote.SetById = (long)Context.User.Id;
                        currentNote.TimeSet = DateTime.Now;
                    }
                    await db.SaveChangesAsync();
                }
                sb.AppendLine($"Note successfully added for server [**{Context.Guild.Name}**] by [**{Context.User.Username}**]!");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error setting note {ex.Message}");
                sb.AppendLine($"Something went wrong adding a note for server [**{Context.Guild.Name}**] :(");
            }
            return(sb.ToString());
        }