public async Task AddHandlers(IUserMessage message, params Tuple <IEmote, Func <ReactionHandlerContext, Task>, bool>[] handlers) { foreach (var handler in handlers) { if (handler.Item3) { if (emojiRemovedFunctions.Any(x => x.Key.Id.Equals(message.Id))) { emojiRemovedFunctions.First(x => x.Key.Id.Equals(message.Id)).Value[handler.Item1] = handler.Item2; } else { emojiRemovedFunctions.Add(message, new Dictionary <IEmote, Func <ReactionHandlerContext, Task> > { { handler.Item1, handler.Item2 } }); } } else { if (emojiAddedFunctions.Any(x => x.Key.Id.Equals(message.Id))) { emojiAddedFunctions.First(x => x.Key.Id.Equals(message.Id)).Value[handler.Item1] = handler.Item2; } else { emojiAddedFunctions.Add(message, new Dictionary <IEmote, Func <ReactionHandlerContext, Task> > { { handler.Item1, handler.Item2 } }); } } } await message.AddReactionsAsync(handlers.Select(x => x.Item1).ToArray()); }
public async Task Help([Summary("(Optional) Get help with this command.")] string command = null) { SocketGuildUser user = Context.Guild.Users.FirstOrDefault(x => x.Id == Context.User.Id); bool isAdmin = (user.Roles.Where(role => role.Permissions.Administrator).ToList().Count != 0 || Context.Guild.OwnerId == user.Id); bool isNona = Context.Guild.Name.Equals(Global.HOME_SERVER, StringComparison.OrdinalIgnoreCase); string prefix = Connections.Instance().GetPrefix(Context.Guild.Id); if (command == null) { List <CommandInfo> validCommands = Global.COMMAND_INFO.Where(cmdInfo => CheckShowCommand(cmdInfo.Name, isAdmin, isNona)).ToList(); IUserMessage msg = await ReplyAsync(embed : BuildGeneralHelpEmbed(validCommands.Take(MAX_COMMANDS).ToList(), prefix, 1)); if (validCommands.Count > MAX_COMMANDS) { helpMessages.Add(msg.Id, new HelpMessage(validCommands)); msg.AddReactionsAsync(HELP_EMOJIS); } } else if (Global.COMMAND_INFO.FirstOrDefault(x => x.Name.Equals(command, StringComparison.OrdinalIgnoreCase) || x.Aliases.Contains(command)) is CommandInfo cmdInfo && CheckShowCommand(cmdInfo.Name, isAdmin, isNona)) { EmbedBuilder embed = new EmbedBuilder(); embed.WithColor(Global.EMBED_COLOR_HELP_RESPONSE); embed.WithTitle($"**{prefix}{cmdInfo.Name} command help**"); embed.WithDescription(cmdInfo.Summary ?? "No description available"); if (cmdInfo.Aliases.Count > 1) { StringBuilder sb = new StringBuilder(); foreach (string alias in cmdInfo.Aliases) { if (!alias.Equals(command, StringComparison.OrdinalIgnoreCase)) { sb.Append($"{alias}, "); } } embed.AddField("Alternate Command:", sb.ToString().TrimEnd().TrimEnd(',')); } if (cmdInfo.Remarks != null) { embed.AddField("**Additional Information:**", cmdInfo.Remarks); } if (cmdInfo.Parameters.Count == 0) { embed.WithFooter("*This command does not take any parameters."); } else { StringBuilder sb = new StringBuilder(); foreach (ParameterInfo param in cmdInfo.Parameters) { embed.AddField($"**<{param.Name}>**", param.Summary ?? "No description available"); sb.Append($" {param.Name}"); } embed.AddField($"**Example:**", $"{prefix}{cmdInfo.Name}{sb}"); } await ReplyAsync(embed : embed.Build()); }
public async Task Poll([Remainder] string args = "") { string[] options = args.Split(','); string message = string.Empty; List <IEmote> emojiCodes = new List <IEmote>(); foreach (string option in options) { // Get the poll option text. message += option.TrimStart() + Environment.NewLine; // Get the poll option reaction. string emojiCode = option.Split('(', ')')[1].Trim(); if (emojiCode.Contains(':')) { // If the reaction is a custom emoji, get the emoji code from the Guild. string customEmojiName = emojiCode.Split(':')[1]; emojiCodes.Add(Context.Guild.Emotes.First(x => x.Name == customEmojiName)); } else { emojiCodes.Add(new Emoji(emojiCode)); } } // Create the poll in the channel. IUserMessage sent = await ReplyAsync(message); // Add reactions to the poll. await sent.AddReactionsAsync(emojiCodes.ToArray()); }
public async static Task UploadToSauce(IMessage message, bool Hell) { var images = message.Attachments; if (images.Count > 0) { IUserMessage mess = message as IUserMessage; await mess.AddReactionsAsync(Utilities.Utilities.MakeEmojiArray("❤️", "⭐")); } foreach (var img in images) { await MakeUpload(img.Url, message.Channel.Name.Replace("-", " "), Hell); } if (message.Embeds.Count > 0) { foreach (Embed emb in message.Embeds) { await MakeUpload(emb.Image.Value.Url, message.Channel.Name.Replace("-", " "), Hell); } IUserMessage mess = message as IUserMessage; await mess.AddReactionsAsync(Utilities.Utilities.MakeEmojiArray("❤️", "⭐")); } }
public static void CreatePaginatedMessage( ulong userId, IUserMessage message, int pageCount, int initialPage, PageAction action, int timeout = 300000, Action onTimeout = null ) { if (pageCount == 1) { return; } message.AddReactionsAsync( new[] { new Emoji(PaginatedMessage.FirstPage), new Emoji(PaginatedMessage.PreviousPage), new Emoji(PaginatedMessage.NextPage), new Emoji(PaginatedMessage.LastPage) } ); var paginatedMessage = new PaginatedMessage(userId, message, pageCount, initialPage, action); ReactionMessageCache.Add( message.Id.ToString(), paginatedMessage, new CacheItemPolicy { SlidingExpiration = TimeSpan.FromMilliseconds(timeout), RemovedCallback = onTimeout == null ? null : (CacheEntryRemovedCallback)(_ => onTimeout()) } ); }
public override async Task Reset() { Battle = new ColossoBattle(); foreach (var k in PlayerMessages.Keys) { await k.DeleteAsync(); } PlayerMessages.Clear(); if (EnemyMessage == null) { await Initialize(); } else { await EnemyMessage.ModifyAsync(c => { c.Content = GetEnemyMessageString(); c.Embed = null; }); await EnemyMessage.RemoveAllReactionsAsync(); _ = EnemyMessage.AddReactionsAsync(new IEmote[] { Emote.Parse("<:Fight:536919792813211648>"), Emote.Parse("<:Battle:536954571256365096>") }); wasJustReset = true; } if (StatusMessage != null) { _ = StatusMessage.DeleteAsync(); StatusMessage = null; } SetNextEnemy(); if (autoTurn != null) { autoTurn.Dispose(); } if (resetIfNotActive != null) { resetIfNotActive.Dispose(); } autoTurn = new Timer() { Interval = 25000, AutoReset = false, Enabled = false }; autoTurn.Elapsed += TurnTimeElapsed; resetIfNotActive = new Timer() { Interval = 120000, AutoReset = false, Enabled = false }; resetIfNotActive.Elapsed += BattleWasNotStartetInTime; Console.WriteLine("Battle was reset."); }
public async Task OpenTicket() { if (await Program.P.db.DoesTicketExist(Context.User.Id, Context.Guild)) { await ReplyAsync(Sentences.chanAlreadyExist); } else if (!await Program.P.db.IsLastMoreThan10Minutes(Context.User.Id)) { await ReplyAsync(Sentences.needWait); } else { string id; IReadOnlyCollection <ITextChannel> chans = await Context.Guild.GetTextChannelsAsync(); do { id = GetRandomId(); } while (chans.Count(x => x.Name == "support-" + id) > 0); ITextChannel chan = await Context.Guild.CreateTextChannelAsync("support-" + id, x => x.CategoryId = 585811641648807936); await chan.AddPermissionOverwriteAsync(Context.User, new OverwritePermissions(viewChannel : PermValue.Allow)); IUserMessage msg = await chan.SendMessageAsync(Sentences.openRequestChan); await msg.AddReactionsAsync(new[] { new Emoji("1⃣"), new Emoji("2⃣"), new Emoji("3⃣"), new Emoji("4⃣") }); await Program.P.db.AddTicket(Context.User.Id, chan.Id, (await ReplyAsync(Sentences.chanCreated("<#" + chan.Id + ">"))).Id, msg.Id, id, Context.Channel.Id); await Context.Message.DeleteAsync(); } }
private async Task HandleReactionInAdd(SocketReaction reaction, IUserMessage msg) { if (reaction.Emote.Equals(OneEmote) && reaction.UserId == P1.User.Id) { P1.Accepted = true; RestartTimer(); } else if (reaction.Emote.Equals(TwoEmote) && reaction.UserId == P2.User.Id) { P2.Accepted = true; RestartTimer(); } if (P1.Accepted && P2.Accepted) { State = ExchangeStatus.AcceptP1; Tips = $"{P1.User.Mention} daj {AcceptEmote} aby zaakceptować, lub {DeclineEmote} aby odrzucić."; await msg.RemoveAllReactionsAsync(); await msg.ModifyAsync(x => x.Embed = BuildEmbed()); await msg.AddReactionsAsync(new IEmote[] { AcceptEmote, DeclineEmote }); } }
public override void Execute(IMessage message) { string[] split = message.Content.Split('\n'); if (split.Length < 2) { DiscordNETWrapper.SendText($"Duuude no I need more Information, or different Information\nHave a look into my HelpMenu ({Prefix}help {CommandLine})", message.Channel).Wait(); return; } string[] pollOptions = split[1].Split(','); if (pollOptions.Length > 9) { DiscordNETWrapper.SendText("Duuude thats too many answer possibilities, 9 should be enough\nIf you want more ask the Discord Devs for a 10 Emoji", message.Channel).Wait(); return; } int i = 0; IUserMessage pollMessage = DiscordNETWrapper.SendEmbed(DiscordNETWrapper.CreateEmbedBuilder($":bar_chart: **{split[0].Remove(0, PrefixAndCommand.Length + 1)}**", pollOptions.Select(x => emotes[i++].Name + " " + x).Aggregate((x, y) => x + "\n" + y)), message.Channel).Result.First(); pollMessage.AddReactionsAsync(emotes.Take(pollOptions.Length).ToArray()).Wait(); return; }
public async Task PollGameRole(IUser user) { user = user ?? Context.User; Poll rolePoll = _poll.CreatePoll(GameElement.Poll.Role(user.Username), GameElement.GetRoleNames().ToList(), Context.User); IUserMessage message = await ReplyAsync(string.Empty, false, rolePoll.Message); await message.AddReactionsAsync(rolePoll.Emojis.Select(e => new Emoji(e)).ToArray()); }
public static async Task <bool> PromptYesNo(this Context ctx, IUserMessage message, IUser user = null, TimeSpan?timeout = null) { await message.AddReactionsAsync(new[] { new Emoji(Emojis.Success), new Emoji(Emojis.Error) }); var reaction = await ctx.AwaitReaction(message, user ?? ctx.Author, (r) => r.Emote.Name == Emojis.Success || r.Emote.Name == Emojis.Error, timeout ?? TimeSpan.FromMinutes(1)); return(reaction.Emote.Name == Emojis.Success); }
protected override async Task InitializeMessageAsync(IUserMessage message) { await message.AddReactionsAsync(Selectables.Keys.ToArray()); if (AllowCancel) { await message.AddReactionAsync(CancelEmote); } }
public async Task SetDefaultReactions(IUserMessage message) { await message.AddReactionsAsync(new[] { Emojis.ThumbsUp, Emojis.KeycapDigits[0], Emojis.KeycapDigits[1], Emojis.KeycapDigits[2] }, retryOptions); }
public async Task InitiateReadyPoll() { Poll readyPoll = _poll.CreatePoll(GameElement.Poll.Ready(), new List <string>(), _client.CurrentUser); IUserMessage message = await DayChannel.SendMessageAsync(string.Empty, false, readyPoll.Message); await message.AddReactionsAsync(readyPoll.Emojis.Select(e => new Emoji(e)).ToArray()); StartMonitoring(CreateMonitor(message.Id, null, MonitorType.Ready)); }
public async Task StartExcommunicatePoll(IUser target, IUser author) { Poll kickPoll = _poll.CreatePoll(GameElement.Poll.Kick(target.Username), new List <string>(), author); IUserMessage message = await DayChannel.SendMessageAsync(string.Empty, false, kickPoll.Message); await message.AddReactionsAsync(kickPoll.Emojis.Select(e => new Emoji(e)).ToArray()); StartMonitoring(CreateMonitor(message.Id, target, MonitorType.Kick)); }
private async Task AttacheDefaultReaction(IUserMessage message) { string[] emojiData = { "⚔️", "✅", "🏁", "❌", "🔄" }; var emojiMatrix = emojiData.Select(x => new Emoji(x)).ToArray(); //foreach (var emoji in emojiMatrix) { await message.AddReactionsAsync(emojiMatrix); } }
public static async Task <bool> PromptYesNo(this Context ctx, IUserMessage message, IUser user = null, TimeSpan?timeout = null) { // "Fork" the task adding the reactions off so we don't have to wait for them to be finished to start listening for presses #pragma warning disable 4014 message.AddReactionsAsync(new IEmote[] { new Emoji(Emojis.Success), new Emoji(Emojis.Error) }); #pragma warning restore 4014 var reaction = await ctx.AwaitReaction(message, user ?? ctx.Author, (r) => r.Emote.Name == Emojis.Success || r.Emote.Name == Emojis.Error, timeout ?? TimeSpan.FromMinutes(1)); return(reaction.Emote.Name == Emojis.Success); }
public async Task AddReactions(IUserMessage message) { var emotes = new IEmote[] { new Emoji(_configuration["UserUpdates:Reactions:Subscribe"]), new Emoji(_configuration["UserUpdates:Reactions:Unsubscribe"]) }; await message.AddReactionsAsync(emotes); }
private async Task Initialize() { EnemyMessage = await BattleChannel.SendMessageAsync(GetEnemyMessageString()); _ = EnemyMessage.AddReactionsAsync(new IEmote[] { Emote.Parse("<:Fight:536919792813211648>"), Emote.Parse("<:Battle:536954571256365096>") }); return; }
/// <summary> /// Sends a "did you mean ...?" style reply. This adds a clickable reaction that triggers an automatic command when clicked by the user that originally did the command within a certain time limit. /// </summary> /// <param name="message">The message to reply to.</param> /// <param name="title">The message title.</param> /// <param name="description">The message description.</param> /// <param name="command">The bot command to imitate if the reaction is clicked.</param> public static IUserMessage SendDidYouMeanReply(IUserMessage message, string title, string description, string command) { IUserMessage sentMessage = message.Channel.SendMessageAsync(embed: GetGenericPositiveMessageEmbed(title, description)).Result; if (sentMessage != null) { sentMessage.AddReactionsAsync(new IEmote[] { new Emoji(Constants.ACCEPT_EMOJI), new Emoji(Constants.DENY_EMOJI) }).Wait(); ReactionsHandler.AddReactable(message, sentMessage, command); } return(sentMessage); }
public async Task DisplayConfigAllAsync() { EmbedBuilder builder = ConfigEmbedBuilder(); _lastConfigMessage = await Context.Channel.SendMessageAsync(string.Empty, false, builder.Build()); _currentPage = 0; (Context.Client as DiscordSocketClient).ReactionAdded += HandleReactionAddedAsync; var emojis = new Emoji[] { new Emoji("\U00002B05"), new Emoji("\U000027A1") }; // Unicode characters for left and right arrows, respectively await _lastConfigMessage.AddReactionsAsync(emojis); }
public AudioClientWrapper( IAudioClient client, IUserMessage message, IAudioConfig globalConfig, IAudioGuildConfig?guildConfig = null) { Message = message; Client = client; if (guildConfig?.AllowReactions ?? globalConfig.AllowReactions) { _ = message.AddReactionsAsync(_emotes); } message.ModifyAsync(m => m.Embed = _readyEmbed); }
public async Task AttachAction(Action action, IUserMessage message) { using var db = data.GetContext(); var id = ActionId(action); if (id < 0) { throw new ArgumentException("Action is not registered. The f**k did you do?"); } await Task.WhenAll( message.AddReactionsAsync(action.Emotes), db.SetAction(message.Id, ActionId(action)) ); }
private async Task AddMuteStamps() { var emotes = _emoteManager.Emotes; var eml = new List <IEmote>(); while (_currentStamps < _players.Count) { _logger.LogDebug($"add emoji({_currentStamps})"); //eml.Add(new Emoji(emotes[_currentStamps])); var e = _emoteManager.GetEmote(_currentStamps); eml.Add(e); _currentStamps++; } await _embedMsg.AddReactionsAsync(eml.ToArray()); }
public void LoadOptions(IUserMessage reply) { if (options != null) { try { _ = reply.AddReactionsAsync(options.Select(s => EUI.ToEmote(s)).ToArray()); } catch (Exception e) { _ = Handlers.UniqueChannels.Instance.SendToLog(e); Log.LogS(e); } } }
/// <summary> /// Sets values for a raid notification message. /// </summary> /// <param name="guild">Guild to set notify message.</param> /// <param name="channel">Registered channel.</param> /// <param name="emotes">Emotes to represent roles.</param> /// <returns></returns> public static async Task SetNotifyMessage(SocketGuild guild, ISocketMessageChannel channel, Emote[] emotes) { foreach (GuildEmote emote in emotes) { await guild.CreateRoleAsync(emote.Name, null, null, false, true, null); } IUserMessage message = await ResponseMessage.SendInfoMessage(channel, "React to this message to be notified when a specific raid is called.\n" + "When the raid bosses change your role will be removed and you will have to re-select desired bosses.\n" + "If you no longer wish to be notified for a boss, re-react for the desired boss."); message.AddReactionsAsync(emotes); Connections.Instance().UpdateNotificationMessage(guild.Id, channel.Id, message.Id); }
public async Task GetCoinsAsync(List <string> options, PollCommandArguments args) { Optional <string> errorMessage = _service.ValidatePollCommandArguments(args, options); if (errorMessage.IsSpecified) { await ReplyAsync(errorMessage.Value); } else { Poll poll = _service.CreatePoll(args, options, Context.User); IUserMessage pollMessage = await ReplyAsync(string.Empty, false, poll.Message); await pollMessage.AddReactionsAsync(poll.Emojis.Select(e => new Emoji(e)).ToArray()); } }
public async Task Poll([Remainder] string questionAndOptions) { string[] parts = questionAndOptions.Split(','); if (parts.Length < 3) { await ReplyAsync("Rossz a kérdés megfogalmazása, használd a !help parancsot további információkért."); } else if (parts.Length > _awailableReactions.Count() + 1) { await ReplyAsync("Túl sok válaszlehetőség max " + _awailableReactions.Count() + " lehet!"); } else { try { string question = parts[0]; string[] answerOptions = parts.ToList().GetRange(1, parts.Length - 1).ToArray(); List <Emoji> usedEmotes = new List <Emoji>(); var emoji = Context.Client.Guilds.SelectMany(g => g.Emotes).ToList(); Console.WriteLine(emoji.Count); StringBuilder answers = new StringBuilder(); for (int i = 0; i < answerOptions.Length; i++) { answers.AppendLine(_awailableReactions[i] + " : " + answerOptions[i]); usedEmotes.Add(_awailableReactions[i]); } var embed = new EmbedBuilder { Color = Color.Gold, Title = question, Description = answers.ToString() }; IUserMessage sent = await ReplyAsync("", false, embed.Build()); await sent.AddReactionsAsync(usedEmotes.ToArray()); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); await ReplyAsync("Üzemzavar bocsi...."); } } }
public async Task StartAsync(ITextChannel textChannel) { if (_locked) { return; } _ = textChannel ?? throw new NullReferenceException("StartAsync"); Message = await textChannel.SendMessageAsync(embed : EmbedUtils.CreatePollEmbed(this)); await Message.AddReactionsAsync(GetEmojis()); SetupTimer(); _timerStart = DateTime.UtcNow; _locked = true; Timer.Start(); }
public async Task WantPlay([Remainder] string message) { if (message == null || message.Trim().Length == 0) { return; } var up = new Emoji("\uD83D\uDC4D"); var off = new Emoji("\uD83D\uDCF4"); string options = up + " - Jövök!" + Environment.NewLine; options += off + " - Off!"; var embed = new EmbedBuilder { Color = Color.Blue, Title = message, Description = options }; IUserMessage sent = await ReplyAsync("", false, embed.Build()); await sent.AddReactionsAsync(new[] { up, off }); }