コード例 #1
0
        public async Task <bool> CheckmarkEmoteUsed(MessageInteractionContext context)
        {
            bool updateMessage = false;

            bool userIsAdmin = context.User.Id == context.Guild.OwnerId || context.User.Roles.Any(role => { return(role.Permissions.Administrator == true); });

            if (!AdminConfirmed && userIsAdmin)
            {
                AdminConfirmed = true;
                updateMessage  = true;
            }

            for (int i = 0; i < Guild.MemberIds.Count; i++)
            {
                if (context.User.Id == Guild.MemberIds[i])
                {
                    ConfirmedMembers[i] = !ConfirmedMembers[i];
                    updateMessage       = true;
                    break;
                }
            }

            if (updateMessage)
            {
                return(await UpdateMessage(context.Message, context.Guild));
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        private async Task <bool> OnConfirm(MessageInteractionContext context)
        {
            if (context.User.Id == NewMember.Id)
            {
                if (MinecraftGuildModel.TryGetGuildOfUser(NewMember.Id, out MinecraftGuild existingGuild, true))
                {
                    EmbedBuilder failure = new EmbedBuilder()
                    {
                        Title       = "Failed",
                        Color       = BotCore.ErrorColor,
                        Description = $"Already in guild \"{(existingGuild.NameAndColorFound ? existingGuild.Name : existingGuild.ChannelId.ToString())}\""
                    };
                    await context.Message.ModifyAsync(MessageProperties =>
                    {
                        MessageProperties.Embed = failure.Build();
                    });
                }
                else if (Guild != null)
                {
                    await MinecraftGuildModel.MemberJoinGuildAsync(Guild, NewMember);

                    EmbedBuilder success = new EmbedBuilder()
                    {
                        Title       = "Success",
                        Color       = Guild.DiscordColor,
                        Description = $"{NewMember.Mention} joined \"{Guild.Name}\""
                    };
                    await context.Message.ModifyAsync(MessageProperties =>
                    {
                        MessageProperties.Embed = success.Build();
                    });
                }
                return(true);
            }
コード例 #3
0
        /// <summary>
        /// Handles reactions added to messages
        /// </summary>
        public static async Task ReactionAddedHandler(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            IUserMessage reactionMessage;

            if (reaction.Message.IsSpecified)
            {
                reactionMessage = reaction.Message.Value;
            }
            else
            {
                reactionMessage = await channel.GetMessageAsync(reaction.MessageId) as IUserMessage;
            }
            SocketTextChannel textChannel = channel as SocketTextChannel;

            if ((reactionMessage != null) && (textChannel != null) && reactionMessage.Author.Id == BotCore.Client.CurrentUser.Id && reaction.User.Value.Id != BotCore.Client.CurrentUser.Id)
            {
                if (InteractiveMessages.TryGetValue(reactionMessage.Id, out InteractiveMessage interactiveMessage))
                {
                    MessageInteractionContext context = new MessageInteractionContext(reaction, reactionMessage, textChannel);
                    if (context.IsDefined)
                    {
                        await interactiveMessage.HandleInteraction(context);
                    }
                }
            }
        }
コード例 #4
0
        public async Task <bool> CrossEmoteUsed(MessageInteractionContext context)
        {
            if (context.User.Id == context.Guild.OwnerId || context.User.Roles.Any(role => { return(role.Permissions.Administrator == true); }))
            {
                EmbedBuilder embed = new EmbedBuilder()
                {
                    Title = $"Founding of Guild \"{Guild.Name}\" - Founding rights denied!",
                    Color = BotCore.ErrorColor
                };
                await context.Message.ModifyAsync(MessageProperties =>
                {
                    MessageProperties.Embed = embed.Build();
                });

                return(true);
            }
            else if (Guild.MemberIds.Contains(context.User.Id))
            {
                EmbedBuilder embed = new EmbedBuilder()
                {
                    Title = $"Founding of Guild \"{Guild.Name}\" - Founding member {context.User.Username} denied!",
                    Color = BotCore.ErrorColor
                };
                await context.Message.ModifyAsync(MessageProperties =>
                {
                    MessageProperties.Embed = embed.Build();
                });

                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #5
0
        public override async Task OnMessageExpire(MessageInteractionContext context)
        {
            EmbedBuilder embed = new EmbedBuilder()
            {
                Title = $"Founding of Guild \"{Guild.Name}\" - Failed due to Timeout!",
                Color = BotCore.ErrorColor
            };

            await context.Message.ModifyAsync(MessageProperties =>
            {
                MessageProperties.Embed = embed.Build();
            });
        }
コード例 #6
0
        private async Task <bool> RemoveMessage(MessageInteractionContext context)
        {
            bool userIsAdmin = context.User.Id == context.Guild.OwnerId || context.User.Roles.Any(role => { return(role.Permissions.Administrator == true); });

            if (userIsAdmin)
            {
                await context.Message.DeleteAsync();

                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #7
0
 private async Task <bool> MarkTaskAsComplete(MessageInteractionContext context)
 {
     if (!Completed)
     {
         Completed = true;
         EmbedBuilder embed = new EmbedBuilder()
         {
             Title       = Title,
             Description = "Completed by " + context.User.Mention,
             Color       = Green
         };
         await context.Message.ModifyAsync(message => { message.Embed = embed.Build(); });
     }
     return(false);
 }
コード例 #8
0
 /// <summary>
 /// Handles an interaction with this message
 /// </summary>
 /// <param name="context">MessageInteraction Context</param>
 public async Task HandleInteraction(MessageInteractionContext context)
 {
     if (ExpirationTime < TimingThread.Millis && ExpirationTime >= 0)
     {
         InteractiveMessageService.RemoveInteractiveMessage(MessageId);
         await OnMessageExpire(context);
     }
     else
     {
         if (await OnAnyEmoteAdded(context))
         {
             InteractiveMessageService.RemoveInteractiveMessage(MessageId);
         }
         else if (Interactions.TryGetValue(context.Emote.Name, out EmoteInteraction interaction))
         {
             await interaction.HandleAction(context);
         }
     }
 }
コード例 #9
0
 /// <summary>
 /// Handles the action
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public async Task HandleAction(MessageInteractionContext context)
 {
     try
     {
         if (InteractiveMessageService.HasInteractiveMessage(MessageId))
         {
             if (InvalidateMessage)
             {
                 InteractiveMessageService.RemoveInteractiveMessage(MessageId);
             }
             if (await Action(context))
             {
                 InteractiveMessageService.RemoveInteractiveMessage(MessageId);
             }
         }
     }
     catch (Exception e)
     {
         await GuildChannelHelper.SendExceptionNotification(e, $"Error handling EmoteInteraction, MessageId `{MessageId}`, Emote {Emote.Name}");
     }
 }
コード例 #10
0
 protected override async Task <bool> OnAnyEmoteAdded(MessageInteractionContext context)
 {
     if (UnicodeEmoteService.TryParseEmoteToInt(context.Emote, out int optionNumber))
     {
         if (optionNumber < Desyncs.First.Options.Count)
         {
             await Desyncs.First.Options[optionNumber].ExecuteAsync();
             if (Desyncs.Count > 1)
             {
                 Desyncs.Index++;
                 await MoveNext(context.Channel, Desyncs);
             }
             else
             {
                 await context.Channel.SendEmbedAsync("All desyncs dealt with!");
             }
             return(true);
         }
     }
     return(false);
 }
コード例 #11
0
#pragma warning disable 1998
        internal static async Task <bool> EmptyMessageInteractionMethod(MessageInteractionContext context)
#pragma warning restore 1998
        {
            return(true);
        }
コード例 #12
0
 protected virtual Task <bool> OnAnyEmoteAdded(MessageInteractionContext context)
 {
     return(Task.FromResult(false));
 }
コード例 #13
0
 public virtual Task OnMessageExpire(MessageInteractionContext context)
 {
     return(context.Message.ModifyAsync(MessageProperties => { MessageProperties.Embed = GenericExpired.Build(); }));
 }