private static bool CheckGiphyEnabled(ICommandContext context) { bool isEnabled = false; string serverName = string.Empty; var guildInfo = context.Guild; if (guildInfo == null) { serverName = context.User.Username; } else { serverName = context.Guild.Name; } using (var db = new DiscbotContext()) { var giphySettings = db.Giphy.FirstOrDefault(g => g.ServerName == serverName); if (giphySettings != null) { if ((bool)giphySettings.GiphyEnabled) { isEnabled = true; } } } return(isEnabled); }
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()); }
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(); } }
private async Task WordFinder(SocketMessage messageDetails) { await Task.Run(async() => { var message = messageDetails as SocketUserMessage; if (!messageDetails.Author.IsBot) { List <WordList> serverWordList = null; using (var db = new DiscbotContext()) { SocketGuild guild = (message.Channel as SocketGuildChannel)?.Guild; serverWordList = db.WordList.AsEnumerable().Where(w => w.ServerId == (long)guild.Id).ToList(); } bool wordFound = false; foreach (var singleWord in serverWordList) { foreach (var content in messageDetails.Content.ToLower().Split(' ')) { if (singleWord.Word.ToLower().Contains(content)) { wordFound = true; } } } if (wordFound) { await messageDetails.DeleteAsync(); } } }); }
//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(); } }); }
public AwaySystem GetAwayUser(string discordUserName) { var awayUser = new AwaySystem(); using (var db = new DiscbotContext()) { awayUser = db.AwaySystem.AsEnumerable().Where(a => a.UserName == discordUserName).FirstOrDefault(); } return(awayUser); }
public async Task <Warnings> GetWarning(ICommandContext context, IGuildUser userWarned) { Warnings warning = null; using (var db = new DiscbotContext()) { warning = db.Warnings.AsEnumerable().Where(w => w.ServerId == (long)context.Guild.Id && w.UserWarnedId == (long)userWarned.Id).FirstOrDefault(); } return(warning); }
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); }
private ServerGreeting GetGreeting(SocketGuildUser user) { ServerGreeting shouldGreet = null; var guildId = user.Guild.Id; using (var db = new DiscbotContext()) { shouldGreet = db.ServerGreetings.AsEnumerable().Where(g => g.DiscordGuildId == (long)guildId).FirstOrDefault(); } return(shouldGreet); }
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(); } } }
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); }
public ChannelOutput GetGuildBotChannel(ulong guildId) { ChannelOutput outputChannel = new ChannelOutput(); using (var db = new DiscbotContext()) { outputChannel = db.ChannelOutputs.FirstOrDefault(o => o.ServerId == (long)guildId); } if (outputChannel == null) { outputChannel = new ChannelOutput(); } return(outputChannel); }
public async Task <string> GetNoteInfo(ICommandContext Context) { StringBuilder sb = new StringBuilder(); using (var db = new DiscbotContext()) { var note = db.Notes.FirstOrDefault(n => n.ServerId == (long)Context.Guild.Id); if (note == null) { sb.AppendLine($"Unable to find a note for server [{Context.Guild.Name}], perhaps try adding one by using {_prefix}set-note \"Note goes here!\""); } else { sb.AppendLine(note.Note1); sb.AppendLine(); sb.Append($"*Note set by [**{note.SetBy}**] on [**{note.TimeSet}**]*"); } } return(sb.ToString()); }
public void SetAwayUser(AwaySystem awayInfo) { var awayUser = new AwaySystem(); using (var db = new DiscbotContext()) { awayUser = db.AwaySystem.AsEnumerable().Where(a => a.UserName == awayInfo.UserName).FirstOrDefault(); if (awayUser == null) { db.AwaySystem.Add(awayInfo); } else { awayUser.Status = awayInfo.Status; awayUser.Message = awayInfo.Message; awayUser.TimeAway = awayInfo.TimeAway; } db.SaveChanges(); } }
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()); }
public AutoRoleServices(DiscbotContext context) { _context = context; }
public ServerServices(DiscbotContext context) { _context = context; }
public async Task ToggleGiphy() { try { StringBuilder sb = new StringBuilder(); string serverName = string.Empty; long serverId = 0; var guildInfo = Context.Guild; var embed = new EmbedBuilder(); if (guildInfo == null) { serverName = Context.User.Username; serverId = (long)Context.User.Id; embed.ThumbnailUrl = Context.User.GetAvatarUrl(); } else { serverName = Context.Guild.Name; serverId = (long)Context.Guild.Id; embed.ThumbnailUrl = Context.Guild.IconUrl; } using (var db = new DiscbotContext()) { var giphySettings = db.Giphy.FirstOrDefault(g => g.ServerName == serverName); if (giphySettings == null) { db.Giphy.Add(new Database.Entities.Giphy { GiphyEnabled = true, ServerId = serverId, ServerName = serverName }); embed.Title = $"Giphy enabled for [**{serverName}**]"; sb.AppendLine($":question:__How to use **{_prefix}giphy**__:question:"); sb.AppendLine(); sb.AppendLine($"**{_prefix}giphy**"); sb.AppendLine($"The above command would get a random image"); sb.AppendLine(); sb.AppendLine($"**{_prefix}giphy Rocket League**"); sb.AppendLine($"The above command would get a random image related to Rocket League"); } else if ((bool)giphySettings.GiphyEnabled) { giphySettings.GiphyEnabled = false; embed.Title = $"Giphy disabled for [**{serverName}**]"; sb.AppendLine(); sb.AppendLine($"{Context.User.Username}, I thought this was America!"); } else { giphySettings.GiphyEnabled = true; embed.Title = $"Giphy enabled for [**{serverName}**]"; sb.AppendLine($":question:__How to use **{_prefix}giphy**__:question:"); sb.AppendLine(); sb.AppendLine($"**{_prefix}giphy**"); sb.AppendLine($"The above command would get a random image"); sb.AppendLine(); sb.AppendLine($"**{_prefix}giphy Rocket League**"); sb.AppendLine($"The above command would get a random image related to Rocket League"); } db.SaveChanges(); } embed.WithColor(new Color(255, 0, 0)); embed.Description = sb.ToString(); await _channelServices.Reply(Context, embed); } catch (Exception ex) { Console.WriteLine($"Giphy toggle error -> [{ex.Message}]"); await _channelServices.Reply(Context, $"Error toggling Giphy command...!"); } }
public RankServices(DiscbotContext context) { _context = context; }