示例#1
0
 public Task ClearReactionsAsync(Snowflake channelId, Snowflake messageId, IEmoji emoji = null, RestRequestOptions options = null)
 => emoji != null
         ? ApiClient.DeleteAllReactionsForEmojiAsync(channelId, messageId, emoji.ReactionFormat, options)
         : ApiClient.DeleteAllReactionsAsync(channelId, messageId, options);
 public RestReactionsRequestEnumerator(RestDiscordClient client,
                                       Snowflake channelId, Snowflake messageId, IEmoji emoji, int limit, Snowflake?startFromId,
                                       RestRequestOptions options)
     : base(client, 100, limit, options)
 {
     _channelId   = channelId;
     _messageId   = messageId;
     _emoji       = emoji;
     _startFromId = startFromId;
 }
示例#3
0
 public RestRequestEnumerator <RestUser> GetReactionEnumerator(Snowflake messageId, IEmoji emoji, int limit, RetrievalDirection?direction = null, Snowflake?startFromId = null)
 => Client.GetReactionEnumerator(Id, messageId, emoji, limit, direction, startFromId);
示例#4
0
 public Task AddReactionAsync(IEmoji emoji, RestRequestOptions options = null)
 => Client.AddReactionAsync(Channel.Id, Id, emoji, options);
示例#5
0
 public RestRequestEnumerable <RestUser> GetReactionsEnumerable(Snowflake messageId, IEmoji emoji, int limit, Snowflake?startFromId = null, RestRequestOptions options = null)
 => Client.GetReactionsEnumerable(Id, messageId, emoji, limit, startFromId, options);
 public Task <IReadOnlyList <RestUser> > GetReactionsAsync(Snowflake channelId, Snowflake messageId, IEmoji emoji, int limit = 100, Snowflake?startFromId = null, RestRequestOptions options = null) => ((IRestDiscordClient)RestClient).GetReactionsAsync(channelId, messageId, emoji, limit, startFromId, options);
示例#7
0
 public bool Equals(IEmoji other)
 => Discord.Comparers.Emoji.Equals(this, other);
示例#8
0
 /// <summary>
 /// Lists custom emoji for a team.
 /// <see href="https://api.slack.com/methods/emoji.list" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='token'>
 /// Authentication token. Requires scope: `emoji:read`
 /// </param>
 public static ListOKResponseModelModelModelModel List(this IEmoji operations, string token = default(string))
 {
     return(operations.ListAsync(token).GetAwaiter().GetResult());
 }
示例#9
0
 public MessageReaction(IEmoji emoji, int count, bool hasOwnReaction)
 {
     Emoji          = emoji;
     Count          = count;
     HasOwnReaction = hasOwnReaction;
 }
示例#10
0
 public abstract ValueTask <Page> GetPageAsync(IEmoji emoji, Snowflake userId);
示例#11
0
 public bool IsKakeraEmoji(IEmoji emoji, out KakeraType kakera) => emoji is ICustomEmoji& _kakeraMap.TryGetValue(emoji.Name, out kakera);
示例#12
0
 public Task ClearReactionsAsync(IEmoji emoji = null, RestRequestOptions options = null)
 => Client.ClearReactionsAsync(Channel.Id, Id, emoji, options);
示例#13
0
 public Task <IReadOnlyList <RestUser> > GetReactionsAsync(IEmoji emoji, int limit = 100, Snowflake?startFromId = null, RestRequestOptions options = null)
 => Client.GetReactionsAsync(Channel.Id, Id, emoji, limit, startFromId, options);
示例#14
0
        public async Task AddRoleAsync(IRole role, IEmoji emojiDefinition)
        {
            if (role.Position > Context.Guild.CurrentMember.Hierarchy || role.Position > ((CachedMember)Context.User).Hierarchy)
            {
                await ReplyAsync("This role is TOO POWERFUL you fool.");

                return;
            }

            if (!Context.Guild.CurrentMember.Permissions.ManageRoles)
            {
                await ReplyAsync("I can't give roles in this server. PLS GIV ME ADMIN");

                return;
            }

            AssignableRole newRole;

            if (emojiDefinition is LocalCustomEmoji lc)
            {
                newRole = new AssignableRole
                {
                    GuildId   = Context.Guild.Id,
                    RoleId    = role.Id,
                    EmojiName = emojiDefinition.Name,
                    Animated  = emojiDefinition.MessageFormat.StartsWith("<a"),
                    EmojiId   = ulong.Parse(emojiDefinition.ReactionFormat.Split(":")[1])
                };
            }
            else if (emojiDefinition is LocalEmoji le)
            {
                newRole = new AssignableRole
                {
                    GuildId   = Context.Guild.Id,
                    RoleId    = role.Id,
                    EmojiName = emojiDefinition.Name,
                    Animated  = false,
                    EmojiId   = null
                };
            }
            else
            {
                return;
            }

            await using (var db = new DataContext())
            {
                var roleMatch = db.Roles.FirstOrDefault(x => x.GuildId == newRole.GuildId && x.RoleId == newRole.RoleId);
                if (roleMatch != null)
                {
                    await ReplyAsync("That role can already be given to users you buffoon.");

                    return;
                }
                var emojiRoleMatch = db.Roles.FirstOrDefault(x => x.GuildId == newRole.GuildId && x.EmojiName == newRole.EmojiName);
                if (emojiRoleMatch != null)
                {
                    await ReplyAsync("That emoji is already associated with a role, imbecile.");

                    return;
                }

                await db.Roles.AddAsync(newRole);

                _cache.Put(newRole, TimeSpan.FromHours(1));

                if (newRole.IsCustomEmoji())
                {
                    _cache.RemoveIgnore <AssignableRole>(newRole.GuildId, newRole.EmojiId);
                }
                else
                {
                    _cache.RemoveIgnore <AssignableRole>(newRole.GuildId, newRole.EmojiName);
                }

                await db.SaveChangesAsync();
                await ReplyAsync(
                    $"Your citizens may now be granted this role, use `{Context.Prefix}getRole {role.Name}` to be granted it.");
            }
        }
        public static Task ClearReactionsAsync(this IMessage message, IEmoji emoji = null, IRestRequestOptions options = null)
        {
            var client = message.GetRestClient();

            return(client.ClearReactionsAsync(message.ChannelId, message.Id, emoji, options));
        }
示例#16
0
        public async Task HandleReactionAsync(ulong userId, ulong messageId, ulong channelId, IEmoji emoji, bool add)
        {
            // TODO: Cache valid reactions to reduce DB calls

            using (var db = new DataContext())
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                if (_cache.ExistsIgnore <ReactableRoleMessage>(messageId))
                {
                    return;
                }

                var messageMatch = _cache.Retrieve <ReactableRoleMessage>(x => x.ChannelId == channelId && x.MessageId == messageId);
                if (messageMatch == null)
                {
                    messageMatch =
                        db.RoleMessages.FirstOrDefault(x => x.ChannelId == channelId && x.MessageId == messageId);
                    if (messageMatch != null)
                    {
                        // Populate cache
                        _cache.Put(messageMatch, TimeSpan.FromHours(1));
                    }
                }

                if (messageMatch == null)
                {
                    _cache.PutIgnore <ReactableRoleMessage>(TimeSpan.FromHours(1), messageId);
                    return;
                }

                AssignableRole roleMatch;
                if (emoji is CustomEmoji ce)
                {
                    if (_cache.ExistsIgnore <AssignableRole>(messageMatch.GuildId, ce.Id.RawValue))
                    {
                        return;
                    }

                    roleMatch = _cache.Retrieve <AssignableRole>(x =>
                                                                 x.GuildId == messageMatch.GuildId && x.EmojiId == ce.Id.RawValue) ??
                                db.Roles.FirstOrDefault(x =>
                                                        x.GuildId == messageMatch.GuildId && x.EmojiId == ce.Id.RawValue);

                    if (roleMatch == null)
                    {
                        _cache.PutIgnore <AssignableRole>(TimeSpan.FromHours(1), messageMatch.GuildId, ce.Id.RawValue);
                        return;
                    }
                }
                else if (emoji is Emoji em)
                {
                    if (_cache.ExistsIgnore <AssignableRole>(messageMatch.GuildId, em.Name))
                    {
                        return;
                    }

                    roleMatch = _cache.Retrieve <AssignableRole>(x =>
                                                                 x.GuildId == messageMatch.GuildId && x.EmojiName == em.Name) ??
                                db.Roles.FirstOrDefault(x =>
                                                        x.GuildId == messageMatch.GuildId && x.EmojiName == em.Name);

                    if (roleMatch == null)
                    {
                        _cache.PutIgnore <AssignableRole>(TimeSpan.FromHours(1), messageMatch.GuildId, em.Name);
                        return;
                    }
                }
                else
                {
                    return;
                }

                _cache.Put(roleMatch, TimeSpan.FromHours(1));
#if DEBUG
                await Bot.SendMessageAsync(channelId, $"{sw.ElapsedMilliseconds}ms elapsed");
#endif
                if (add)
                {
                    await Bot.GrantRoleAsync(messageMatch.GuildId, userId, roleMatch.RoleId);
                }
                else
                {
                    await Bot.RevokeRoleAsync(messageMatch.GuildId, userId, roleMatch.RoleId);
                }
            }
        }
 public RestRequestEnumerable <RestUser> GetReactionsEnumerable(Snowflake channelId, Snowflake messageId, IEmoji emoji, int limit, Snowflake?startFromId = null, RestRequestOptions options = null) => ((IRestDiscordClient)RestClient).GetReactionsEnumerable(channelId, messageId, emoji, limit, startFromId, options);
示例#18
0
 public ButtonAttribute(ulong emojiId, string name = null, bool isAnimated = false)
 {
     Emoji = new LocalCustomEmoji(emojiId, name, isAnimated);
 }
 public Task AddReactionAsync(Snowflake channelId, Snowflake messageId, IEmoji emoji, RestRequestOptions options       = null) => ((IRestDiscordClient)RestClient).AddReactionAsync(channelId, messageId, emoji, options);
        public static Task RemoveOwnReactionAsync(this IMessageChannel channel, Snowflake messageId, IEmoji emoji, IRestRequestOptions options = null)
        {
            var client = channel.GetRestClient();

            return(client.RemoveOwnReactionAsync(channel.Id, messageId, emoji, options));
        }
示例#21
0
 public Task RemoveMemberReactionAsync(Snowflake memberId, IEmoji emoji, RestRequestOptions options = null)
 => Client.RemoveMemberReactionAsync(Channel.Id, Id, memberId, emoji, options);
示例#22
0
 internal static ICustomStatusActivity CreateCustomStatusActivity(string name, string text, IEmoji emoji = null)
 {
     return(new CustomStatusActivity(name, text, emoji));
 }
示例#23
0
 internal Reaction(int count, bool me, IEmoji emoji)
 {
     Count = count;
     Me    = me;
     Emoji = emoji;
 }
        public static Task RemoveReactionAsync(this IMessage message, IEmoji emoji, Snowflake userId, IRestRequestOptions options = null)
        {
            var client = message.GetRestClient();

            return(client.RemoveReactionAsync(message.ChannelId, message.Id, emoji, userId, options));
        }
示例#25
0
 public Task ClearReactionsAsync(Snowflake messageId, IEmoji emoji = null, RestRequestOptions options = null)
 => Client.ClearReactionsAsync(Id, messageId, emoji, options);
        public static IPagedEnumerable <IUser> EnumerateReactions(this IMessage message, IEmoji emoji, int limit, Snowflake?startFromId = null, IRestRequestOptions options = null)
        {
            var client = message.GetRestClient();

            return(client.EnumerateReactions(message.ChannelId, message.Id, emoji, limit, startFromId, options));
        }
示例#27
0
 public Task RemoveOwnReactionAsync(Snowflake messageId, IEmoji emoji, RestRequestOptions options = null)
 => Client.RemoveOwnReactionAsync(Id, messageId, emoji, options);
        public static Task <IReadOnlyList <IUser> > FetchReactionsAsync(this IMessage message, IEmoji emoji, int limit = 100, Snowflake?startFromId = null, IRestRequestOptions options = null)
        {
            var client = message.GetRestClient();

            return(client.FetchReactionsAsync(message.ChannelId, message.Id, emoji, limit, startFromId, options));
        }
示例#29
0
 public Task <IReadOnlyList <RestUser> > GetReactionsAsync(Snowflake messageId, IEmoji emoji, int limit = 100, RetrievalDirection?direction = null, Snowflake?startFromId = null, RestRequestOptions options = null)
 => Client.GetReactionsAsync(Id, messageId, emoji, limit, direction, startFromId, options);
示例#30
0
        internal async Task <IReadOnlyList <RestUser> > InternalGetReactionsAsync(Snowflake channelId, Snowflake messageId, IEmoji emoji, int limit = 100, Snowflake?startFromId = null, RestRequestOptions options = null)
        {
            var models = await ApiClient.GetReactionsAsync(channelId, messageId, emoji.ReactionFormat, limit, startFromId, options).ConfigureAwait(false);

            return(models.ToReadOnlyList(this, (x, @this) => new RestUser(@this, x)));
        }