private async Task HandleReaction(SocketReaction Reaction) { if (Reaction.User.Value.IsBot || Reaction.UserId == Reaction.Message.Value.Author.Id) { return; } var conf = Configuration.Load(); if (Reaction.Channel.Id == conf.SupportRequestsChannel) { if (Reaction.Emote.Name.ToLowerInvariant() == conf.RequestAcceptEmote.ToLowerInvariant()) { await DeleteMessage(Reaction.Message.Value); Requests--; await SendDirectMessage(Reaction.User.Value.Mention + " reacted to your request for support and he is willing to help! You can talk with him on Direct Messages or in <#" + conf.SupportChannel + ">", Reaction.Message.Value.Author); await SendDirectMessage(Reaction.Message.Value.Content, Reaction.User.Value); await SendMessage(Reaction.User.Value.Mention + " accepted to help " + Reaction.Message.Value.Author.Mention + ".\nThe help topic is: \n" + Reaction.Message.Value.Content, ClientInstance.Guilds.ToList()[0].Id, conf.LogChannel); } else if ((Reaction.Emote.Name.ToLowerInvariant() == conf.RequestDownvoteEmote.ToLowerInvariant() && Reaction.Message.Value.Reactions[Reaction.Emote].ReactionCount - 1 >= conf.DownvotesForDenial) || ((HasRole(conf.StaffRole, Reaction.UserId, ClientInstance.Guilds.ToList()[0].Id) || HasRole(conf.SupporterRole, Reaction.UserId, ClientInstance.Guilds.ToList()[0].Id)) && Reaction.Emote.Name.ToLowerInvariant() == conf.AdminDenyEmote.ToLowerInvariant())) { await DeleteMessage(Reaction.Message.Value); Requests--; await SendMessage("A successful vote (or admin vote) was passed to deny help request from " + Reaction.Message.Value.Author.Mention + ".\nThe help topic is: \n" + Reaction.Message.Value.Content, ClientInstance.Guilds.ToList()[0].Id, conf.LogChannel); } else if ((Reaction.Emote.Name.ToLowerInvariant() == conf.RequestBanEmote.ToLowerInvariant() && Reaction.Message.Value.Reactions[Reaction.Emote].ReactionCount - 1 >= conf.BanvotesForRemoval) || ((HasRole(conf.StaffRole, Reaction.UserId, ClientInstance.Guilds.ToList()[0].Id) || HasRole(conf.SupporterRole, Reaction.UserId, ClientInstance.Guilds.ToList()[0].Id)) && Reaction.Emote.Name.ToLowerInvariant() == conf.AdminBanEmote.ToLowerInvariant())) { await DeleteMessage(Reaction.Message.Value); Requests--; var guild = ClientInstance.Guilds.ToList()[0]; await guild.GetUser(Reaction.Message.Value.Author.Id).AddRoleAsync(guild.GetRole(conf.RequestBannedRole)); await SendMessage("A successful vote (or admin vote) was passed to ban " + Reaction.Message.Value.Author.Mention + " from support requests.\nThe help topic is: \n" + Reaction.Message.Value.Content, ClientInstance.Guilds.ToList()[0].Id, conf.LogChannel); } } else if (Reaction.Channel.Id == conf.GeneralChannel) { if (Reaction.Emote.Name.ToLowerInvariant() == conf.RequestDownvoteEmote.ToLowerInvariant() && (HasRole(conf.StaffRole, Reaction.UserId, ClientInstance.Guilds.ToList()[0].Id) || HasRole(conf.SupporterRole, Reaction.UserId, ClientInstance.Guilds.ToList()[0].Id))) { var learning = Learning.Load(); if (learning.NoHelp.Exists(k => CalculateSimilarity(Reaction.Message.Value.Content, k) > 0.80)) { return; } learning.NoHelp.Add(Reaction.Message.Value.Content); learning.SaveJson(); await SendMessage(Reaction.Message.Value.Author.Mention + ", please don't ask for help in this channel.\nWe do not provide help/support in this channel since it is meant for talking about general stuff.\n If you want help, go in <#" + conf.SupportChannel + "> and ask there for help after tagging the support role.\n\nThank you in advance.", ClientInstance.Guilds.ToList()[0].Id, Reaction.Message.Value.Channel.Id); await SendMessage("New message added to anti-general-help list: \n" + Reaction.Message.Value.Content, ClientInstance.Guilds.ToList()[0].Id, conf.LogChannel); } } }
private async Task HandleMessage(SocketCommandContext Context) { if (Context == null || Context.Message.Author.IsBot || Context.IsPrivate) { return; } if (IsCommand(Context.Message.Content)) { HandleCommand(Context); return; } var config = Configuration.Load(); if (IsSpam(Context.Message, out string res) && !HasRole(config.SupporterRole, Context.Message.Author.Id, Context.Guild.Id) && !HasRole(config.StaffRole, Context.Message.Author.Id, Context.Guild.Id)) { if (WarnedSpammers.Exists(k => k == Context.Message.Author.Id)) { await Context.Guild.AddBanAsync(Context.Message.Author, 7, "Spamming. Anti-Spam ban.", new RequestOptions() { AuditLogReason = "Anti-spam ban" }); await SendMessage(Context.Message.Author.Mention + " banned for spamming.", Context.Guild.Id, Context.Channel.Id); await SendMessage("Anti-spam triggered on " + Context.Message.Author.Id + ".\nReason: " + (res ?? "N/A") + ".\nMessage sent: " + Context.Message.Content + ".\nMessage ID (For discord reports if needed):" + Context.Message.Id + ".\nAction: Banned.", Context.Guild.Id, config.LogChannel); WarnedSpammers.RemoveAll(k => k == Context.Message.Author.Id); } else { await SendMessage(Context.Message.Author.Mention + " cease your spam immediately. Failure to do so will result in a ban. This is your first **AND FINAL** warning.", Context.Guild.Id, Context.Channel.Id); await SendMessage("Anti-spam triggered on " + Context.Message.Author.Id + ".\nReason: " + (res ?? "N/A") + ".\nMessage sent: " + Context.Message.Content + ".\nMessage ID (For discord reports if needed):" + Context.Message.Id + ".\nAction: Warned.", Context.Guild.Id, config.LogChannel); WarnedSpammers.Add(Context.Message.Author.Id); } return; } if (Context.Channel.Id == config.GeneralChannel) { if (Context.Message.MentionedRoles.ToList().Exists(k => k.Id == config.SupporterRole)) { await DeleteMessage(Context.Message); await SendMessage(Context.Message.Author.Mention + ", please do not tag the supporter role in this channel. Only tag them in <#" + config.SupportChannel + ">. Thank you in advance.", Context.Guild.Id, Context.Channel.Id); } var learning = Learning.Load(); if (learning.NoHelp.Exists(k => CalculateSimilarity(Context.Message.Content, k) > 0.80)) { await SendMessage(Context.Message.Author.Mention + ", please don't ask for help in this channel.\nWe do not provide help/support in this channel since it is meant for talking about general stuff.\n If you want help, go in <#" + config.SupportChannel + "> and ask there for help after tagging the support role.\n\nThank you in advance.", Context.Guild.Id, Context.Channel.Id); } } else if (Context.Channel.Id == config.SupportChannel) { if (!HasRole(config.StaffRole, Context.Message.Author.Id, Context.Guild.Id) && (config.SupporterAntiTagBypass && !HasRole(config.SupporterRole, Context.Message.Author.Id, Context.Guild.Id))) { if (Context.Message.MentionedUsers.Count > 0) { await DeleteMessage(Context.Message); var msg = Context.Message.Content.Split().ToList(); foreach (var s in msg.ToList()) { if (s.StartsWith("<@")) { msg.Remove(s); } else if (string.Equals(s, "@everyone")) { msg.Remove(s); } } if (msg.Count == 0) { return; } SendMessage(Context.Message.Author + " please do not tag anyone in support channels. They will respond when they can. Thank you.", Context.Guild.Id, Context.Channel.Id, 10); SendMessage(Context.Message.Author + " Says: " + string.Join(" ", msg), Context.Guild.Id, Context.Channel.Id); return; } } } else if (Context.Channel.Id == config.SupportRequestsChannel) { var emotes = Context.Guild.Emotes.ToList(); var emoteUp = emotes.Find(k => k.Name.ToLowerInvariant() == config.RequestAcceptEmote.ToLowerInvariant()); var emoteDown = emotes.Find(k => k.Name.ToLowerInvariant() == config.RequestDownvoteEmote.ToLowerInvariant()); var emoteBan = emotes.Find(k => k.Name.ToLowerInvariant() == config.RequestBanEmote.ToLowerInvariant()); var emoteAdminBan = emotes.Find(k => k.Name.ToLowerInvariant() == config.AdminBanEmote.ToLowerInvariant()); var emoteAdminDeny = emotes.Find(k => k.Name.ToLowerInvariant() == config.AdminDenyEmote.ToLowerInvariant()); if (emoteUp != null) { await Context.Message.AddReactionAsync(emoteUp); } else { await Context.Message.AddReactionAsync(new Emoji(config.RequestAcceptEmote)); } if (emoteDown != null) { await Context.Message.AddReactionAsync(emoteDown); } else { await Context.Message.AddReactionAsync(new Emoji(config.RequestDownvoteEmote)); } if (emoteBan != null) { await Context.Message.AddReactionAsync(emoteBan); } else { await Context.Message.AddReactionAsync(new Emoji(config.RequestBanEmote)); } if (emoteAdminBan != null) { await Context.Message.AddReactionAsync(emoteAdminBan); } else { await Context.Message.AddReactionAsync(new Emoji(config.AdminBanEmote)); } if (emoteAdminDeny != null) { await Context.Message.AddReactionAsync(emoteAdminDeny); } else { await Context.Message.AddReactionAsync(new Emoji(config.AdminDenyEmote)); } Requests++; } }