예제 #1
0
        public async Task AcceptLinkInviteCommand(SocketTextChannel localChannel, ulong linkId)
        {
            var globalData = MemorySystem.memory.GetData <ChannelLinkingSystem, ChannelLinkingGlobalData>();

            if (!globalData.links.TryGetValue(linkId, out var link))
            {
                throw new BotError("Invalid link id.");
            }

            var localIds = new ServerChannelIds(localChannel.Guild.Id, localChannel.Id);

            if (!link.invitedChannels.Contains(localIds))
            {
                throw new BotError("There are no invites to that link associated with this channel.");
            }

            var localServer     = localChannel.Guild;
            var localServerData = localServer.GetMemory().GetData <ChannelLinkingSystem, ChannelLinkingServerData>();

            localServerData.channelLinks[localChannel.Id] = linkId;

            if (!link.connectedChannels.Contains(localIds))
            {
                link.connectedChannels.Add(localIds);
            }

            link.invitedChannels.Remove(localIds);

            string Notification = $"This channel is now linked with channel `{localChannel.Name}` from server `{localServer.Name}`! :confetti_ball::confetti_ball::confetti_ball:";

            for (int i = 0; i < link.connectedChannels.Count; i++)
            {
                var ids = link.connectedChannels[i];

                if ((ids.serverId == localServer.Id && ids.channelId == localChannel.Id) || !ids.TryGetTextChannel(out var channel))
                {
                    continue;
                }

                await channel.SendMessageAsync(Notification);
            }

            string channelList = string.Join(
                "\r\n",
                link.connectedChannels
                .Where(ids => ids.channelId != localChannel.Id)
                .Select(ids => ids.TryGetChannel(out var channel) ? $"{channel.Guild.Name}/#{channel.Name}" : "Unknown")
                );

            MessageSystem.IgnoreMessage(await localChannel.SendMessageAsync($"This channel is now linked with the following channels: ```\r\n{channelList}\r\n```\r\n:confetti_ball::confetti_ball::confetti_ball:"));
        }
예제 #2
0
        public async Task Delete()
        {
            ulong id = message.Id;

            if (!MessageSystem.MessageIgnored(id))
            {
                MessageSystem.IgnoreMessage(id);

                if (socketTextChannel == null || server.CurrentUser.HasChannelPermission(socketTextChannel, DiscordPermission.ManageMessages))
                {
                    await message.DeleteAsync();
                }
            }
        }
예제 #3
0
        public async Task ClearCommand(SocketTextChannel channel, uint amount)
        {
            var context = Context;
            var server  = context.server;

            server.CurrentUser.RequirePermission(channel, DiscordPermission.ManageMessages);

            int highestRole = server.GetUser(MopBot.client.CurrentUser.Id).Roles.Max(r => r.Position);

            var utcNow   = DateTime.UtcNow.AddMinutes(1);           //+1 min
            var messages = (await channel.GetMessagesAsync((int)amount + 1).FlattenAsync())
                           .Where(m => m != null && (m.Author?.Id == MopBot.client.CurrentUser.Id || ((utcNow - m.Timestamp.UtcDateTime).TotalDays < 14 && (m.Author as SocketGuildUser)?.Roles?.All(r => r.Position < highestRole) == true)));

            MessageSystem.IgnoreMessage(context.message.Id);

            await channel.DeleteMessagesAsync(messages);
        }
예제 #4
0
        public async Task ClearCommand(SocketTextChannel channel, uint amount, ulong bottomMessageId = 0)
        {
            var context = Context;
            var server  = context.server;

            server.CurrentUser.RequirePermission(channel, DiscordPermission.ManageMessages);

            int highestRole = server.GetUser(MopBot.client.CurrentUser.Id).Roles.Max(r => r.Position);
            var utcNow      = DateTime.UtcNow.AddMinutes(1);        //+1 min
            var messageList = new List <IMessage>();

            if (bottomMessageId != 0)
            {
                amount--;

                messageList.Add(await channel.GetMessageAsync(bottomMessageId));
            }

            messageList.AddRange(
                (await channel.GetMessagesAsync((int)amount + 1).FlattenAsync()).Where(m => {
                if (m == null)
                {
                    return(false);
                }

                if (m.Author?.Id != MopBot.client.CurrentUser.Id)
                {
                    if ((utcNow - m.Timestamp.UtcDateTime).TotalDays >= 14 || ((m.Author as SocketGuildUser)?.Roles?.All(r => r.Position < highestRole)) != true)
                    {
                        return(false);
                    }
                }

                return(true);
            })
                );

            MessageSystem.IgnoreMessage(context.message.Id);

            await channel.DeleteMessagesAsync(messageList);
        }