public async Task <RuntimeResult> UnsubscribeFromThread() { if (CommandHandler.FeatureFlagDisabled(FeatureFlag.MODMAIL)) { return(CustomResult.FromIgnored()); } var bot = Global.Bot; using (var db = new Database()) { var existing = db.ThreadSubscribers.AsQueryable().Where(sub => sub.ModMailThreadId == Context.Channel.Id && sub.UserId == Context.User.Id); if (existing.Count() == 0) { return(CustomResult.FromError("You are not subscribed!")); } } using (var db = new Database()) { var existing = db.ThreadSubscribers.AsQueryable().Where(sub => sub.ModMailThreadId == Context.Channel.Id && sub.UserId == Context.User.Id).First(); db.ThreadSubscribers.Remove(existing); db.SaveChanges(); } await Task.CompletedTask; return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> Purge(int messageCount) { if (messageCount > 100) { return(CustomResult.FromError("You cannot purge more than 100 messages at a time")); } // Check if the amount provided by the user is positive. if (messageCount <= 0) { return(CustomResult.FromError("You cannot purge a negative number")); } var messages = await Context.Channel.GetMessagesAsync(messageCount).FlattenAsync(); var filteredMessages = messages.Where(x => (DateTimeOffset.UtcNow - x.Timestamp).TotalDays <= 14); // Get the total amount of messages. var count = filteredMessages.Count(); // Check if there are any messages to delete. if (count == 0) { return(CustomResult.FromError("Nothing to delete.")); } else { await(Context.Channel as ITextChannel).DeleteMessagesAsync(filteredMessages); await ReplyAndDeleteAsync($"Done. Removed {count} {(count > 1 ? "messages" : "message")}."); return(CustomResult.FromSuccess()); } }
public async Task <RuntimeResult> NewsAsync([Remainder] string news) { var guild = Context.Guild; var user = (SocketGuildUser)Context.Message.Author; var newsChannel = guild.GetTextChannel(Global.Channels["news"]); var newsRole = guild.GetRole(Global.Roles["news"]); var journalistRole = guild.GetRole(Global.Roles["journalist"]); if (news.Contains("@everyone") || news.Contains("@here") || news.Contains("@news")) { return(CustomResult.FromError("Your news article contained one or more illegal pings!")); } if (!user.Roles.Contains(journalistRole)) { return(CustomResult.FromError("Only Journalists can post news.")); } await newsRole.ModifyAsync(x => x.Mentionable = true); await newsChannel.SendMessageAsync(news + Environment.NewLine + Environment.NewLine + newsRole.Mention + Environment.NewLine + "- " + Context.Message.Author); await newsRole.ModifyAsync(x => x.Mentionable = false); return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> BanAsync(IGuildUser user, [Remainder] string reason = null) { if (user.IsBot) { return(CustomResult.FromError("You can't ban bots.")); } if (user.GuildPermissions.PrioritySpeaker) { return(CustomResult.FromError("You can't ban staff.")); } try { const string banMessage = "You were banned on r/OnePlus for the following reason: {0}\n" + "If you believe this to be a mistake, please send an appeal e-mail with all the details to [email protected]"; await user.SendMessageAsync(string.Format(banMessage, reason)); await Context.Guild.AddBanAsync(user, 0, reason); return(CustomResult.FromSuccess()); } catch (Exception ex) { // may not be needed // await Context.Guild.AddBanAsync(user, 0, reason); return(CustomResult.FromError(ex.Message)); } }
public async Task <RuntimeResult> SubscribeToThread() { if (CommandHandler.FeatureFlagDisabled(FeatureFlag.MODMAIL)) { return(CustomResult.FromIgnored()); } var bot = Global.Bot; using (var db = new Database()) { var existing = db.ThreadSubscribers.AsQueryable().Where(sub => sub.ModMailThreadId == Context.Channel.Id && sub.UserId == Context.User.Id); if (existing.Count() > 0) { return(CustomResult.FromError("You are already subscribed!")); } } var subscription = new ThreadSubscriber(); subscription.ModMailThreadId = Context.Channel.Id; subscription.UserId = Context.User.Id; using (var db = new Database()) { db.ThreadSubscribers.Add(subscription); db.SaveChanges(); } await Task.CompletedTask; return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> SteampAsync([Remainder] string user) { await Context.Message.AddReactionAsync(Global.Emotes[Global.OnePlusEmote.SUCCESS].GetAsEmote()); var request = (HttpWebRequest)WebRequest.Create(string.Format(BadgeUrl, user)); using (var response = await request.GetResponseAsync()) using (var stream = response.GetResponseStream()) { if (stream == null) { return(CustomResult.FromError("Could not establish a connection to the Steam API")); } using (var fs = File.Open("output.png", FileMode.Create, FileAccess.Write, FileShare.Read)) { await stream.CopyToAsync(fs); } await Context.Channel.SendFileAsync("output.png"); } File.Delete("output.png"); return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> BanAsync(IGuildUser user, [Remainder] string reason = null) { if (CommandHandler.FeatureFlagDisabled(FeatureFlag.MODERATION)) { return(CustomResult.FromIgnored()); } if (user.IsBot) { return(CustomResult.FromError("You can't ban bots.")); } if (user.GuildPermissions.PrioritySpeaker) { return(CustomResult.FromError("You can't ban staff.")); } if (reason == null) { reason = "No reason provided."; } try { try { const string banDMMessage = "You were banned on r/OnePlus for the following reason: {0}\n" + "If you believe this to be a mistake, please send an appeal e-mail with all the details to [email protected]"; await user.SendMessageAsync(string.Format(banDMMessage, reason)); } catch (HttpException) { await Context.Channel.SendMessageAsync("Seems like user disabled DMs, cannot send message about the ban."); } await Context.Guild.AddBanAsync(user, 0, reason); MuteTimerManager.UnMuteUserCompletely(user.Id); var banLogChannel = Context.Guild.GetTextChannel(Global.PostTargets[PostTarget.BAN_LOG]); var banlog = new EmbedBuilder() .WithColor(9896005) .WithTitle("⛔️ Banned User") .AddField("User", Extensions.FormatUserNameDetailed(user), true) .AddField("By", Extensions.FormatUserNameDetailed(Context.User), true) .AddField("Reason", reason) .AddField("Link", Extensions.FormatLinkWithDisplay("Jump!", Context.Message.GetJumpUrl())); await banLogChannel.SendMessageAsync(embed : banlog.Build()); return(CustomResult.FromSuccess()); } catch (Exception ex) { // may not be needed // await Context.Guild.AddBanAsync(user, 0, reason); return(CustomResult.FromError(ex.Message)); } }
public async Task <RuntimeResult> HandleRemindInput(params string[] arguments) { if (arguments.Length < 1) { return(CustomResult.FromError("The correct usage is `;remind <duration> <text>`")); } string durationStr = arguments[0]; TimeSpan span = Extensions.GetTimeSpanFromString(durationStr); DateTime targetTime = DateTime.Now.Add(span); string reminderText; if (arguments.Length > 1) { string[] reminderParts = new string[arguments.Length - 1]; Array.Copy(arguments, 1, reminderParts, 0, arguments.Length - 1); reminderText = string.Join(" ", reminderParts); } else { return(CustomResult.FromError("You need to provide a text.")); } var author = Context.Message.Author; var guild = Context.Guild; var reminder = new Reminder(); reminder.RemindText = Extensions.RemoveIllegalPings(reminderText); reminder.RemindedUserId = author.Id; reminder.TargetDate = targetTime; reminder.ReminderDate = DateTime.Now; reminder.ChannelId = Context.Channel.Id; reminder.MessageId = Context.Message.Id; using (var db = new Database()) { db.Reminders.Add(reminder); db.SaveChanges(); if (targetTime <= DateTime.Now.AddMinutes(60)) { var difference = targetTime - DateTime.Now; ReminderTimerManger.RemindUserIn(author.Id, difference, reminder.ID); reminder.ReminderScheduled = true; } db.SaveChanges(); } await Context.Channel.SendMessageAsync($"{Context.User.Mention} Scheduled reminder id {reminder.ID}."); return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> DeleteMessage(params string[] parameters) { if (parameters.Length < 1) { return(CustomResult.FromError("Required parameter: <messageId>")); } ulong messageId = (ulong)Convert.ToUInt64(parameters[0]); await new ModMailManager().DeleteMessage(messageId, Context.Channel, Context.User); return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> RemoveFromChannelGroup(string groupName, [Remainder] string text) { var parts = text.Split(' '); if (parts.Length < 1) { return(CustomResult.FromError("syntax <name> <mentioned channels to be added>")); } new ChannelManager().removeChannelsFromGroup(groupName, Context.Message); await Task.CompletedTask; return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> SetReact(int chance) { if (chance < 0 || chance > 100) { return(CustomResult.FromError("The chance must be between 0 and 100")); } else { await Database.GetServerSettings().SetReactChance((long)Context.Guild.Id, chance); await ReplyAsync(Context.User.Mention + " You have set the react chance to `" + chance + "%`."); return(CustomResult.FromSuccess()); } }
public static async Task <CustomResult> UnMuteUser(IGuildUser user) { // will be replaced with a better handling in the future if (!Global.Roles.ContainsKey("voicemuted") || !Global.Roles.ContainsKey("textmuted")) { return(CustomResult.FromError("Configure the voicemuted and textmuted roles correctly. Check your Db!")); } var muteRole = user.Guild.GetRole(Global.Roles["voicemuted"]); await user.RemoveRoleAsync(muteRole); muteRole = user.Guild.GetRole(Global.Roles["textmuted"]); await user.RemoveRoleAsync(muteRole); return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> DisableModMailForUser(IGuildUser user, params string[] arguments) { if (arguments.Length < 1) { return(CustomResult.FromError("You need to provide a duration")); } var durationStr = arguments[0]; TimeSpan mutedTime = Extensions.GetTimeSpanFromString(durationStr); var until = DateTime.Now + mutedTime; new ModMailManager().DisableModmailForUser(user, until); await Task.CompletedTask; return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> NewsAsync([Remainder] string news) { if (CommandHandler.FeatureFlagDisabled(FeatureFlag.NEWS)) { return(CustomResult.FromIgnored()); } var guild = Context.Guild; var user = (SocketGuildUser)Context.Message.Author; var newsChannel = guild.GetTextChannel(Global.PostTargets[PostTarget.NEWS]) as SocketNewsChannel; var newsRole = guild.GetRole(Global.Roles["news"]); if (news.Contains("@everyone") || news.Contains("@here") || news.Contains("@news")) { return(CustomResult.FromError("Your news article contained one or more illegal pings!")); } await newsRole.ModifyAsync(x => x.Mentionable = true); IMessage posted; var messageToPost = news + Environment.NewLine + Environment.NewLine + newsRole.Mention + Environment.NewLine + "- " + Context.Message.Author; try { if (Context.Message.Attachments.Any()) { var builder = new EmbedBuilder(); if (Context.Message.Attachments.Any()) { var attachment = Context.Message.Attachments.First(); builder.WithImageUrl(attachment.ProxyUrl).Build(); } posted = await newsChannel.SendMessageAsync(messageToPost, embed : builder.Build()); } else { posted = await newsChannel.SendMessageAsync(messageToPost); } } finally { await newsRole.ModifyAsync(x => x.Mentionable = false); } Global.NewsPosts[Context.Message.Id] = posted.Id; return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> NewsAsync([Remainder] string news) { var guild = Context.Guild; var user = (SocketGuildUser)Context.Message.Author; var needsAttachments = Context.Message.Attachments.Count() > 0; var newsChannel = guild.GetTextChannel(Global.PostTargets[PostTarget.NEWS]) as SocketNewsChannel; var newsRole = guild.GetRole(Global.Roles["news"]); if (news.Contains("@everyone") || news.Contains("@here") || news.Contains("@news")) { return(CustomResult.FromError("Your news article contained one or more illegal pings!")); } await newsRole.ModifyAsync(x => x.Mentionable = true); IMessage posted; var messageToPost = news + Environment.NewLine + Environment.NewLine + newsRole.Mention + Environment.NewLine + "- " + Context.Message.Author; try { if (needsAttachments) { var attachment = Context.Message.Attachments.First(); WebClient client = new WebClient(); client.DownloadFile(attachment.Url, attachment.Filename); posted = await newsChannel.SendFileAsync(attachment.Filename, messageToPost); File.Delete(attachment.Filename); } else { posted = await newsChannel.SendMessageAsync(messageToPost); } } finally { await newsRole.ModifyAsync(x => x.Mentionable = false); } Global.NewsPosts[Context.Message.Id] = posted.Id; return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> DisableModMailForUser(IGuildUser user, [Remainder] string duration) { if (CommandHandler.FeatureFlagDisabled(FeatureFlag.MODMAIL)) { return(CustomResult.FromIgnored()); } if (duration is null) { return(CustomResult.FromError("You need to provide a duration.")); } TimeSpan mutedTime = Extensions.GetTimeSpanFromString(duration); var until = DateTime.Now + mutedTime; new ModMailManager().DisableModmailForUser(user, until); await new ModMailManager().SendModmailMuteNofication(user, Context.User, until); return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> KickAsync(IGuildUser user, [Remainder] string reason = null) { if (user.IsBot) { return(CustomResult.FromError("You can't kick bots.")); } if (user.GuildPermissions.PrioritySpeaker) { return(CustomResult.FromError("You can't kick staff.")); } await user.KickAsync(reason); return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> RollDice(int dice = 1) { List <string> emojis = new List <string>() { "one", "two", "three", "four", "five", "six" }; if (dice > 100) { return(CustomResult.FromError("You may only roll up to 100 dice at a time")); } else if (dice <= 0) { dice = 1; } string diceMessage = Context.User.Mention + " :game_die: You just rolled a "; string diceEmoji = ""; int total = 0; Random rnd = new Random(); for (int i = 0; i < dice; i++) { int die = rnd.Next(1, 7); diceMessage += "**" + die + "** +"; diceEmoji += ":" + emojis[die - 1] + ":"; total += die; } diceMessage = diceMessage.Remove(diceMessage.Length - 2, 2); diceMessage += "!"; await ReplyAsync(diceMessage + " " + diceEmoji); if (dice > 1) { string dice_stats = "`Total: " + total + "`\n`Average: " + total / dice + "`"; await ReplyAsync(dice_stats); } return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> EditMessage(params string[] parameters) { if (parameters.Length < 2) { return(CustomResult.FromError("Required parameters: <messageId> <new text>")); } ulong messageId = (ulong)Convert.ToUInt64(parameters[0]); string newText = ""; string[] reasons = new string[parameters.Length - 1]; Array.Copy(parameters, 1, reasons, 0, parameters.Length - 1); newText = string.Join(" ", reasons); await new ModMailManager().EditMessage(newText, messageId, Context.Channel, Context.User); await Context.Message.DeleteAsync(); return(CustomResult.FromIgnored()); }
public async Task <RuntimeResult> PurgeAsync([Remainder] double delmsg) { if (CommandHandler.FeatureFlagDisabled(FeatureFlag.MODERATION)) { return(CustomResult.FromIgnored()); } if (delmsg > 100 || delmsg <= 0) { return(CustomResult.FromError("Use a number between 1-100")); } int delmsgInt = (int)delmsg; ulong oldmessage = Context.Message.Id; var isInModmailContext = Global.ModMailThreads.Exists(ch => ch.ChannelId == Context.Channel.Id); // Download all messages that the user asks for to delete var messages = await Context.Channel.GetMessagesAsync(oldmessage, Direction.Before, delmsgInt).FlattenAsync(); var saveMessagesToDelete = new List <IMessage>(); if (isInModmailContext) { var manager = new ModMailManager(); foreach (var message in messages) { var messageCanBeDeleted = await manager.DeleteMessageInThread(Context.Channel.Id, message.Id, false); if (messageCanBeDeleted) { saveMessagesToDelete.Add(message); } } } else { saveMessagesToDelete.AddRange(messages); } await((ITextChannel)Context.Channel).DeleteMessagesAsync(saveMessagesToDelete); await Context.Message.DeleteAsync(); return(CustomResult.FromIgnored()); }
public async Task <RuntimeResult> HandleUnRemindInput(ulong reminderId) { await Task.CompletedTask; using (var db = new Database()) { var reminder = db.Reminders.Where(re => re.ID == reminderId && re.RemindedUserId == Context.User.Id).FirstOrDefault(); if (reminder != null) { reminder.Reminded = true; db.SaveChanges(); return(CustomResult.FromSuccess()); } else { return(CustomResult.FromError("Reminder not known or not started by you.")); } } }
public async Task <RuntimeResult> Kick(IGuildUser user, [Remainder] string reason = "") { if (user.Id == Context.Client.CurrentUser.Id) { return(CustomResult.FromError($"Silly { Context.User.Mention}, I can't kick myself!")); } if (user.Id == Context.User.Id) { return(CustomResult.FromError($"{ Context.User.Mention}, you can't kick yourself")); } string reasonString = (reason.Length == 0) ? "No reason given." : reason; Embed announceE = new EmbedBuilder() { Title = "User Kicked", Color = Color.Green, Description = $"{user.Mention} was kick from the server.", Fields = new List <EmbedFieldBuilder>() { new EmbedFieldBuilder() { Name = "Reason", Value = reasonString } } }.Build(); Embed dmE = new EmbedBuilder() { Title = $"You have been kicked from {Context.Guild.Name} by {Context.User.Username}", Color = Color.Red, Description = reasonString, Timestamp = DateTime.Now }.Build(); await(await user.GetOrCreateDMChannelAsync()).SendMessageAsync(embed: dmE); await user.BanAsync(reason : reasonString); await ReplyAsync(embed : announceE); return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> SetStars(string input) { ulong amount = 0; await Task.Delay(25); if (ulong.TryParse(input, out amount) && amount > 0) { using (var db = new Database()){ var point = db.PersistentData.First(entry => entry.Name == "starboard_stars"); point.Value = amount; db.SaveChanges(); } Global.StarboardStars = amount; return(CustomResult.FromSuccess()); } else { return(CustomResult.FromError("whole numbers > 0 only")); } }
public async Task <RuntimeResult> PurgeAsync([Remainder] double delmsg) { if (delmsg > 100 || delmsg <= 0) { return(CustomResult.FromError("Use a number between 1-100")); } int delmsgInt = (int)delmsg; ulong oldmessage = Context.Message.Id; // Download all messages that the user asks for to delete var messages = await Context.Channel.GetMessagesAsync(oldmessage, Direction.Before, delmsgInt).FlattenAsync(); await((ITextChannel)Context.Channel).DeleteMessagesAsync(messages); await Task.Delay(950); await Context.Message.DeleteAsync(); return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> ChooseAsync(params string[] argArray) { if (CommandHandler.FeatureFlagDisabled(FeatureFlag.UTILITY)) { return(CustomResult.FromIgnored()); } if (argArray == null || argArray.Length == 0) { return(CustomResult.FromError("I can't choose nothingness.")); } var answer = argArray[Global.Random.Next(argArray.Length)]; if (answer.Contains("@everyone") || answer.Contains("@here") || Context.Message.MentionedRoles.Count > 0) { return(CustomResult.FromError("Your command contained one or more illegal pings!")); } await Context.Channel.SendMessageAsync($"I've chosen {answer}"); return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> CreateEmoteInDatabase(string name, [Remainder] string _) { var emoteTags = Context.Message.Tags.Where(t => t.Type == TagType.Emoji); if (!emoteTags.Any()) { return(CustomResult.FromError("No emote found.")); } var uncastedEmote = emoteTags.Select(t => (Emote)t.Value).First(); if (uncastedEmote is Emote) { var emote = uncastedEmote as Emote; using (var db = new Database()) { var sameKey = db.Emotes.AsQueryable().Where(e => e.Key == name); StoredEmote emoteToChange; if (sameKey.Any()) { emoteToChange = sameKey.First(); } else { emoteToChange = new StoredEmote(); db.Emotes.Add(emoteToChange); } emoteToChange.Animated = emote.Animated; emoteToChange.EmoteId = emote.Id; emoteToChange.Name = emote.Name; emoteToChange.Key = name; emoteToChange.Custom = true; db.SaveChanges(); } } await Task.CompletedTask; return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> KickAsync(IGuildUser user, [Remainder] string reason = null) { if (CommandHandler.FeatureFlagDisabled(FeatureFlag.MODERATION)) { return(CustomResult.FromIgnored()); } if (user.IsBot) { return(CustomResult.FromError("You can't kick bots.")); } if (user.GuildPermissions.PrioritySpeaker) { return(CustomResult.FromError("You can't kick staff.")); } await user.KickAsync(reason); MuteTimerManager.UnMuteUserCompletely(user.Id); return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> SetTrackingStatus(string name, Boolean value) { if (CommandHandler.FeatureFlagDisabled(FeatureFlag.EMOTE_TRACKING)) { return(CustomResult.FromIgnored()); } using (var db = new Database()) { var sameKey = db.Emotes.AsQueryable().Where(e => e.Key == name); if (sameKey.Any()) { StoredEmote emoteToChange = sameKey.First(); emoteToChange.TrackingDisabled = value; db.SaveChanges(); return(CustomResult.FromSuccess()); } else { return(CustomResult.FromError("Emote not found.")); } } }
public async Task <RuntimeResult> SetSlowModeTo(string slowModeConfig) { if (CommandHandler.FeatureFlagDisabled(FeatureFlag.MODERATION)) { return(CustomResult.FromIgnored()); } var channelObj = Context.Guild.GetTextChannel(Context.Channel.Id); if (slowModeConfig == "off") { await channelObj.ModifyAsync(pro => pro.SlowModeInterval = 0); } else { var span = Extensions.GetTimeSpanFromString(slowModeConfig); if (span > TimeSpan.FromHours(6)) { return(CustomResult.FromError("Only values between 1 second and 6 hours allowed.")); } await channelObj.ModifyAsync(pro => pro.SlowModeInterval = (int)span.TotalSeconds); } return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> DisableCurrentThread(params string[] arguments) { var durationStr = arguments[0]; string note; if (arguments.Length > 1) { string[] noteParts = new string[arguments.Length - 1]; Array.Copy(arguments, 1, noteParts, 0, arguments.Length - 1); note = string.Join(" ", noteParts); } else { return(CustomResult.FromError("You need to provide a note.")); } TimeSpan mutedTime = Extensions.GetTimeSpanFromString(durationStr); var until = DateTime.Now + mutedTime; var manager = new ModMailManager(); await manager.LogForDisablingAction(Context.Channel, note, until); manager.DisableModMailForUserWithExistingThread(Context.Channel, until); return(CustomResult.FromIgnored()); }