public static async void RtxLondonAsync(SocketMessage message, CommandContext context, DiscordSocketClient client) { bool found = false; await DiscordFunctions.DeleteSpecificMessage(message); if (Validation.IsUserAuthenticated(message, "guardian-london-18") == false) { foreach (var user in client.GetGuild(358283239053590528).Users) { if (message.Author.Id == user.Id) { await DiscordFunctions.RoleTask(context, "guardian-london-18", user.Id.ToString()); found = true; } } } if (found == true) { var ThumbsUp = new Discord.Emoji("👍"); await context.Message.AddReactionAsync(ThumbsUp); } else { await message.Channel.SendMessageAsync(message.Author.Mention + " You are not a London Guardian if you think this is a mistake please contact an @Admin"); } }
public static async Task PerformAsync(UnifiedContext context, ulong messageId, string emoji, DataBase db) { var guildList = Send.GuildList(context); var task = await Task.WhenAll(guildList.SelectMany(x => x.TextChannels).Select(async x => { try { var message = await x.GetMessageAsync(messageId); return(message); } catch { return(null); } })); var r = task.Where(x => x != null); if (r.Count() == 0) { await Send.SendErrorWithDeleteReaction(context, "message not found"); return; } // test for simple emoji (😃) try { var d = new Discord.Emoji(emoji); await r.First().AddReactionAsync(d); await Send.SendSentEmoteIfCommand(context); return; } catch (Discord.Net.HttpException) {} // look for custom discord emotes var emote = guildList.SelectMany(x => x.Emotes).FirstOrDefault(x => $":{x.Name}:".IndexOf( emoji, StringComparison.OrdinalIgnoreCase) != -1); if (emote != null) { await r.First().AddReactionAsync(emote); await Send.SendSentEmoteIfCommand(context); } else { await Send.SendErrorWithDeleteReaction(context, "Emoji not found. To send a custom emote, use the emote's name."); } return; }
public override async Task <bool> ReactionAddedAsync() { if (!(base.Context.Channel.Name?.Contains("bot-spam") ?? false)) { return(false); } var emote = base.Context.Reaction.Emote switch { // For this to work, the bot has to be in the same server, the emote is from // Because of this, banhammer wont work because the bot is not in the same server Discord.Emote em => $"<:{em.Name}:{em.Id}>", Discord.Emoji emoji => $"{emoji.Name}", _ => "" }; await ReplyAsync($"Reaction added! '{emote}'"); return(true); }
public static async void GuardianAuth(SocketMessage message, CommandContext context, Events Event) { bool found = false; if (Validation.IsUserAuthenticated(message, Event.Event) == false) { // Open database (or create if not exits) using (var db = new LiteDatabase(@"Guardians.db")) { var Guardians = db.GetCollection <UserData>("Guardians"); UserData Guardian = null; foreach (var Guard in Guardians.FindAll()) { if (Guard.DiscordUsername.ToLower().Trim().Contains(message.Author.Username.ToLower() + "#" + message.Author.Discriminator.ToString().ToLower())) { Guardian = Guard; break; } } if (Guardian != null) { if (Guardian.DiscordUsername.ToLower() == message.Author.Username.ToLower() + "#" + message.Author.Discriminator.ToString()) { Guardians.Update(Guardian); await DiscordFunctions.RoleTask(context, "Guardian-" + Guardian.Event, message.Author.Id.ToString()); found = true; } } } } if (found == true) { var ThumbsUp = new Discord.Emoji("👍"); await context.Message.AddReactionAsync(ThumbsUp); } else { await message.Channel.SendMessageAsync(message.Author.Mention + " You are not a Guardian if you think this is a mistake please contact an @Admin"); } }
public async Task RemindMe([Remainder] string message) { try { var input = message.Split(' '); DateTime reminderTime = DateTime.Now; string reminderMessage = ""; // ToDo Make Regex to extract time // Make Extract time and message a function // Handle exact time if (input[0].Contains(':')) { // !Remindme HH:mm {message} if (!DateTime.TryParse(input[0], out reminderTime)) { throw new Exception("Error - Unable to Parse DateTime, correct command usage: !Remindme HH:mm {message}"); } foreach (var msg in input.Skip(1)) { reminderMessage += msg + " "; } } // Handle commands else { // !Remindme -d {int : days} -h {int : hours} -m {int : minutes} {string : message} // Not all commands must be included. for (int i = 0; i < input.Count(); i++) { switch (input[i]) { // Days case "-d": if (!int.TryParse(input[i + 1], out int days)) { throw new Exception("Error - Unable to Parse Days. Command -d"); } reminderTime.AddDays(days); i++; break; // Hours case "-h": if (!int.TryParse(input[i + 1], out int hours)) { throw new Exception("Error - Unable to Parse Hours. Command -h"); } reminderTime.AddHours(hours); i++; break; // Minutes case "-m": if (!int.TryParse(input[i + 1], out int minutes)) { throw new Exception("Error - Unable to Parse Minutes. Command -m"); } reminderTime.AddMinutes(minutes); i++; break; default: reminderMessage += input[i] + " "; break; } } } var reminder = new Reminder(Context.User.Mention, Context.Channel.Id.ToString(), reminderTime, reminderMessage); await _data.InsertReminder(reminder); var emote = new Discord.Emoji("thumbsup"); await Context.Message.AddReactionAsync(emote); } catch (Exception ex) { await ReplyAsync(ex.Message); } }