private async Task OnReactionChanged(IEmote emote, ReactionListener.Action action) { if (emote.Equals(Damage)) { Damaged = !Damaged; } else { if (emote.Equals(CurrentTab)) { CurrentIndex = (CurrentIndex + 1) % NormalCGs[CurrentTab].Count; } else { CurrentIndex = 0; CurrentTab = emote; } } var newUrl = Damaged ? DamagedCGs[CurrentTab][CurrentIndex] : NormalCGs[CurrentTab][CurrentIndex]; if (newUrl != CurrentUrl) { CurrentUrl = newUrl; await UpdateMessage(); } }
/// <summary> /// Adds a function for the specified emote, for the specified message to the handler. /// </summary> /// <param name="message">The message to listen to</param> /// <param name="emote">The emote to listen for</param> /// <param name="function">The function to execute</param> /// <param name="clear"></param> /// <returns></returns> public async Task AddHandler(IUserMessage message, IEmote emote, Func <ReactionHandlerContext, Task> function, bool onRemove = false) { if (onRemove) { if (emojiRemovedFunctions.Any(x => x.Key.Id.Equals(message.Id))) { emojiRemovedFunctions.First(x => x.Key.Id.Equals(message.Id)).Value[emote] = function; } else { emojiRemovedFunctions.Add(message, new Dictionary <IEmote, Func <ReactionHandlerContext, Task> > { { emote, function } }); } } else { if (emojiAddedFunctions.Any(x => x.Key.Id.Equals(message.Id))) { emojiAddedFunctions.First(x => x.Key.Id.Equals(message.Id)).Value[emote] = function; } else { emojiAddedFunctions.Add(message, new Dictionary <IEmote, Func <ReactionHandlerContext, Task> > { { emote, function } }); } } if (!emote.Equals(DefaultEmote) && !message.Reactions.ContainsKey(emote) && !onRemove) { await message.AddReactionAsync(emote); } }
/// <inheritdoc /> public async Task <bool> ConsumeEmoteAsync([NotNull] IEmote emote) { if (emote.Equals(Exit)) { this.Interactive.RemoveReactionCallback(this.Message); await this.Message.DeleteAsync().ConfigureAwait(false); return(true); } if (emote.Equals(Info)) { await DisplayHelpTextAsync(); return(false); } switch (this.State) { case KinkWizardState.CategorySelection: { await ConsumeCategoryInteractionAsync(emote); break; } case KinkWizardState.KinkPreference: { await ConsumePreferenceInteractionAsync(emote); break; } default: { throw new ArgumentOutOfRangeException(); } } return(false); }
public async Task <bool> HandleCallbackAsync(SocketReaction reaction) { IEmote emote = reaction.Emote; if (emote.Equals(options.First)) { page = 1; } else if (emote.Equals(options.Next)) { if (page >= pages) { return(false); } ++page; } else if (emote.Equals(options.Previous)) { if (page <= 1) { return(false); } --page; } else if (emote.Equals(options.Last)) { page = pages; } else if (emote.Equals(options.Cancel)) { await Message.DeleteAsync().ConfigureAwait(false); return(true); } _ = Message.RemoveReactionAsync(reaction.Emote, reaction.User.Value); await UpdateAsync().ConfigureAwait(false); return(false); }
public async Task <bool> HandleCallbackAsync(SocketReaction reaction) { IEmote emote = reaction.Emote; if (emote.Equals(Options.First)) { page = 1; } else if (emote.Equals(Options.Next)) { if (page >= pages) { return(false); } ++page; } else if (emote.Equals(Options.Back)) { if (page <= 1) { return(false); } --page; } else if (emote.Equals(Options.Last)) { page = pages; } else if (emote.Equals(Options.Stop)) { await Message.DeleteAsync().ConfigureAwait(false); return(true); } await RenderAsync().ConfigureAwait(false); return(false); }
public static int EmojiToVoteNumber(IEmote moji) { int i = 0; foreach (IEmote emoji in VoteMoji) { if (moji.Equals(emoji)) { return(i); } i++; } return(-1); }
private async Task ConsumePreferenceInteractionAsync([NotNull] IEmote emote) { if (emote.Equals(Back)) { this.State = KinkWizardState.CategorySelection; await UpdateVisibleMessage(); return; } KinkPreference?preference = null; if (emote.Equals(Fave)) { preference = KinkPreference.Favourite; } if (emote.Equals(Like)) { preference = KinkPreference.Like; } if (emote.Equals(Maybe)) { preference = KinkPreference.Maybe; } if (emote.Equals(Never)) { preference = KinkPreference.No; } if (emote.Equals(NoPreference)) { preference = KinkPreference.NoPreference; } if (!(preference is null)) { await SetCurrentKinkPreference(preference.Value); var getNextKinkResult = await this.Kinks.GetNextKinkByCurrentFListIDAsync(this.Database, this.CurrentFListKinkID); if (!getNextKinkResult.IsSuccess) { this.CurrentFListKinkID = -1; this.State = KinkWizardState.CategorySelection; await this.Feedback.SendConfirmationAndDeleteAsync(this.Context, this.Interactive, "All done in that category!"); } else { this.CurrentFListKinkID = (int)getNextKinkResult.Entity.FListID; } await UpdateVisibleMessage(); } }
private string GetDiscordRole(IEmote emote, string messageType) { XmlDocument doc = new XmlDocument(); doc.Load(xmlFile); XmlNodeList nodeList = doc.SelectNodes($"/Messages/{messageType}/*"); foreach (XmlNode node in nodeList) { if (emote.Equals(new Emoji(node.SelectSingleNode("Icon").InnerText))) { return(node.SelectSingleNode("Name").InnerText); } } return(string.Empty); }
public static void OnReactionAdded(SocketReaction inEvent) { lock (_reactionListenersLockObj) { IUser user = inEvent.User.Value; if (_reactionListeners.TryGetValue(user, out List <Reaction> list)) { ulong msg = inEvent.MessageId; IEmote emote = inEvent.Emote; foreach (Reaction r in list) { if (r.Message.Id == msg && emote.Equals(r.Emote)) { _reactionListeners.Remove(user); r.ClickFunc.Invoke(); // Do not return Task because we do not want to block the main thread return; } } } } }
public static bool IsRightEnd(IEmote moji) { return(moji.Equals((CommandMoji[6] as IEmote))); }
public static bool IsLeft(IEmote moji) { return(moji.Equals((CommandMoji[4] as IEmote))); }
public static bool IsStop(IEmote moji) { return(moji.Equals((CommandMoji[0] as IEmote))); }
public static bool IsReset(IEmote moji) { return(moji.Equals((CommandMoji[1] as IEmote))); }
private async Task ConsumeCategoryInteractionAsync([NotNull] IEmote emote) { if (emote.Equals(Next)) { if (this.CurrentCategoryOffset + 3 >= this.Categories.Count) { return; } this.CurrentCategoryOffset += 3; } else if (emote.Equals(Previous)) { if (this.CurrentCategoryOffset - 3 < 0) { this.CurrentCategoryOffset = 0; return; } this.CurrentCategoryOffset -= 3; } else if (emote.Equals(First)) { if (this.CurrentCategoryOffset == 0) { return; } this.CurrentCategoryOffset = 0; } else if (emote.Equals(Last)) { int newOffset; if (this.Categories.Count % 3 == 0) { newOffset = this.Categories.Count - 3; } else { newOffset = this.Categories.Count - (this.Categories.Count % 3); } if (newOffset <= this.CurrentCategoryOffset) { return; } this.CurrentCategoryOffset = newOffset; } else if (emote.Equals(EnterCategory)) { if (!this.Categories.Any()) { await this.Feedback.SendWarningAndDeleteAsync ( this.Context, this.Interactive, "There aren't any categories in the database.", TimeSpan.FromSeconds(10) ); return; } await this.Feedback.SendConfirmationAndDeleteAsync ( this.Context, this.Interactive, "Please enter a category name.", TimeSpan.FromSeconds(45) ); var message = await this.Interactive.NextMessageAsync(this.Context, timeout : TimeSpan.FromSeconds(45)); var tryStartCategoryResult = await OpenCategory(message.Content); if (!tryStartCategoryResult.IsSuccess) { await this.Feedback.SendWarningAndDeleteAsync ( this.Context, this.Interactive, tryStartCategoryResult.ErrorReason, TimeSpan.FromSeconds(10) ); return; } } await UpdateVisibleMessage(); }
public async Task HandleReaction(SocketReaction reaction, IGuildUser user, ulong guildId, string raidId) { if (!Raids.ContainsKey(raidId)) { return; } Raid raid = Raids[raidId]; IUserMessage userMessage = (IUserMessage)await reaction.Channel.GetMessageAsync(raid.MessageId); IEmote emote = reaction.Emote; if (emote.Equals(Constants.SignOffEmoji)) { RemoveUser(raid.RaidId, user.Id); SaveRaids(); await userMessage.ModifyAsync(msg => msg.Embed = raid.CreateRaidMessage()); await userMessage.RemoveReactionAsync(reaction.Emote, user); return; } ulong userId = user.Id; if (_userService.GetAccounts(guildId, userId, raid.AccountType).Count == 0) { await UserExtensions.SendMessageAsync(user, $"No Account found, please add an Account with \"!user add {raid.AccountType} <AccountName>\".\n" + "\n**This command only works on a server.**"); return; } if (emote.Equals(Constants.FlexEmoji)) { if (!_conversationService.UserHasConversation(user.Id)) { _conversationService.OpenSignUpConversation(this, reaction, user, raid, Constants.Availability.Flex); } } else if (raid.Users.ContainsKey(userId)) { if (emote.Equals(Constants.SignOnEmoji)) { if (raid.IsAvailabilityChangeAllowed(userId, Constants.Availability.Yes)) { raid.Users[userId].Availability = Constants.Availability.Yes; } } else if (emote.Equals(Constants.UnsureEmoji)) { raid.Users[userId].Availability = Constants.Availability.Maybe; } else if (emote.Equals(Constants.BackupEmoji)) { raid.Users[userId].Availability = Constants.Availability.Backup; } } else if (!_conversationService.UserHasConversation(user.Id)) { if (emote.Equals(Constants.SignOnEmoji)) { _conversationService.OpenSignUpConversation(this, reaction, user, raid, Constants.Availability.Yes); } else if (emote.Equals(Constants.UnsureEmoji)) { _conversationService.OpenSignUpConversation(this, reaction, user, raid, Constants.Availability.Maybe); } else if (emote.Equals(Constants.BackupEmoji)) { _conversationService.OpenSignUpConversation(this, reaction, user, raid, Constants.Availability.Backup); } } SaveRaids(); await userMessage.ModifyAsync(msg => msg.Embed = raid.CreateRaidMessage()); await userMessage.RemoveReactionAsync(reaction.Emote, user); }
public async Task <bool> HandleCallbackAsync(SocketReaction reaction) { IEmote emote = reaction.Emote; if (emote.Equals(options.First)) { page = 1; } else if (emote.Equals(options.Next)) { if (page >= pages) { return(false); } ++page; } else if (emote.Equals(options.Back)) { if (page <= 1) { return(false); } --page; } else if (emote.Equals(options.Last)) { page = pages; } else if (emote.Equals(options.Stop)) { await Message.DeleteAsync().ConfigureAwait(false); return(true); } else if (emote.Equals(options.Jump)) { _ = Task.Run(async() => { Criteria <SocketMessage> criteria = new Criteria <SocketMessage>() .AddCriterion(new EnsureSourceChannelCriterion()) .AddCriterion(new EnsureFromUserCriterion(reaction.UserId)) .AddCriterion(new EnsureIsIntegerCriterion()); SocketMessage response = await Interactive.NextMessageAsync(Context, criteria, TimeSpan.FromSeconds(15)); int request = int.Parse(response.Content); if (request < 1 || request > pages) { _ = response.DeleteAsync().ConfigureAwait(false); await Interactive.ReplyAndDeleteAsync(Context, options.Stop.Name); return; } page = request; _ = response.DeleteAsync().ConfigureAwait(false); await RenderAsync().ConfigureAwait(false); }); } else if (emote.Equals(options.Info)) { await Interactive.ReplyAndDeleteAsync(Context, options.InformationText, timeout : options.InfoTimeout); return(false); } _ = Message.RemoveReactionAsync(reaction.Emote, reaction.User.Value); await RenderAsync().ConfigureAwait(false); return(false); }