public async Task ListAllMutes(CommandParameters parameters)
        {
            var mutes = Android.Moderation.MutesByUser;

            if (mutes.Count == 0)
            {
                await parameters.Reply("nobody is muted (excluding manual mutes)");

                return;
            }
            var    now    = DateTime.UtcNow;
            string toSend = "at the time of this message...\n";

            foreach (var item in mutes.OrderBy(i => i.Value.Expiration.Ticks))
            {
                var user = Android.Client.GetUser(item.Key);
                if (user == null)
                {
                    continue;
                }

                toSend += $"{user.Username}#{user.Discriminator} is muted for {Utilities.TimeSpanToText(item.Value.Expiration - now)}\n";
            }
            await parameters.Reply(toSend);
        }
        private async Task SetChannelBan(CommandParameters parameters, bool ban)
        {
            var channels = await Android.Guild.GetChannelsAsync();

            var users             = parameters.SocketMessage.MentionedUsers;
            var mentionedChannels = parameters.SocketMessage.MentionedChannels;
            var guild             = await Android.Client.Rest.GetGuildAsync(Android.GuildID);

            foreach (var channel in mentionedChannels)
            {
                foreach (var user in users)
                {
                    var guildUser = await guild.GetUserAsync(user.Id);

                    var result = await Android.Moderation.SetChannelBan(channel, guildUser, ban, channels);

                    if (!result)
                    {
                        await parameters.Reply($"could not find an appropriate muting role for <#{channel.Id}>");
                    }
                    else
                    {
                        await parameters.Reply($"{user.Username} has been {(ban ? "banned" : "unbanned")} from <#{channel.Id}>");
                    }
                }
            }
        }
        public async Task Mute(CommandParameters parameters)
        {
            var users   = parameters.SocketMessage.MentionedUsers;
            var channel = parameters.SocketMessage.Channel;

            if (users == null || users.Count == 0)
            {
                await parameters.Reply("no users specified");

                return;
            }

            var parsedDuration = Utilities.ParseTimeFromText(parameters.ContentWithoutTriggerAndCommand);
            var duration       = parsedDuration ?? TimeSpan.FromMinutes(DefaultMuteDurationInMinutes);

            if (!parsedDuration.HasValue)
            {
                await parameters.Reply("no duration specified, falling back to " + DefaultMuteDurationInMinutes + " minutes");
            }

            var guild = await Android.Client.Rest.GetGuildAsync(Android.GuildID);

            foreach (var user in users)
            {
                var gU = await guild.GetUserAsync(user.Id);

                await Android.Moderation.Mute(gU, channel as ITextChannel, duration);
            }
        }
Esempio n. 4
0
        public async Task Say(CommandParameters parameters)
        {
            var message = parameters.ContentWithoutTriggerAndCommand;

            bool  specifiesChannel = message.EndsWith(">");
            ulong channelId        = parameters.SocketMessage.Channel.Id;

            if (specifiesChannel)
            {
                Regex regex   = new Regex(@"(in <#\d+>)");
                var   matches = regex.Matches(message.ToLower());
                if (matches.Count != 0)
                {
                    var  match           = matches.Last();
                    bool successfulParse = ulong.TryParse(new string(match.Value.Where(c => char.IsDigit(c)).ToArray()), out channelId);
                    if (!successfulParse)
                    {
                        await parameters.Reply("something went wrong");
                    }
                    else
                    {
                        message = message.Substring(0, message.Length - match.Length);
                    }
                }
            }

            var channel = parameters.Instance.Client.GetChannel(channelId);

            if (channel is SocketTextChannel tc)
            {
                await tc.SendMessageAsync(message);
            }
        }
        private async Task SetInterrogationStatus(CommandParameters parameters, bool state)
        {
            var users = parameters.SocketMessage.MentionedUsers;
            var role  = Android.Guild.GetRole(interrogationRole);
            var guild = await Android.Client.Rest.GetGuildAsync(Android.GuildID);

            if (role == null)
            {
                await parameters.Reply("no interrogation role set... should probably tell an admin");

                return;
            }

            foreach (var item in users)
            {
                var gu = await guild.GetUserAsync(item.Id);

                if (state)
                {
                    await gu.AddRoleAsync(role);
                }
                else
                {
                    await gu.RemoveRoleAsync(role);
                }
            }

            if (state)
            {
                string       reply;
                const string suffix = " ready for interrogation";
                if (users.Count > 1)
                {
                    reply = string.Join(", ", users.Select(u => u.Username)) + " are" + suffix;
                }
                else
                {
                    reply = users.First().Username + " is" + suffix;
                }

                await parameters.Reply(reply);
            }
            else
            {
                await parameters.Reply("come back soon!");
            }
        }
Esempio n. 6
0
        public async Task Ping(CommandParameters p)
        {
            var now   = DateTime.UtcNow;
            var time  = p.SocketMessage.Timestamp.UtcDateTime;
            var delay = now - time;

            await p.Reply($"pong! {Math.Round(delay.TotalMilliseconds, 3)} ms");
        }
Esempio n. 7
0
        public async Task Maths(CommandParameters parameters)
        {
            try
            {
                var result = Parser.Parse(parameters.ContentWithoutTriggerAndCommand.ToLower());

                var safeReply = Utilities.ReplaceMentions(parameters.ContentWithoutTriggerAndCommand);
                await parameters.Reply($"{safeReply} = {result.ToString(CultureInfo.InvariantCulture)}");
            }
            catch (InfinityException)
            {
                await parameters.Reply("infinity");
            }
            catch (NaNException)
            {
                await parameters.Reply("the result was not a number");
            }
            catch (Exception)
            {
                await parameters.Reply("i don't understand the expression");
            }
        }
Esempio n. 8
0
        public async Task GreetingResponse(CommandParameters parameters)
        {
            var responses = new[] {
                "hi",
                ":)",
                "hello",
                "o/",
                "o//",
                "hi :)"
            };

            var i = rand.Next(0, responses.Length);

            await parameters.Reply(responses[i]);
        }
Esempio n. 9
0
        public async Task ArchiveChannel(CommandParameters parameters)
        {
            const int MaxMessageCount = 10000;

            var channels = parameters.SocketMessage.MentionedChannels;

            if (channels == null || channels.Count == 0)
            {
                var a = new List <SocketGuildChannel>()
                {
                    parameters.SocketMessage.Channel as SocketGuildChannel
                };
                channels = a.AsReadOnly();
            }

            var now = DateTime.UtcNow;

            await parameters.Reply("working on it...");

            var isTyping = parameters.SocketMessage.Channel.EnterTypingState();

            foreach (var item in channels)
            {
                if (item is not ITextChannel tc)
                {
                    continue;
                }

                string file     = string.Empty;
                var    messages = tc.GetMessagesAsync(MaxMessageCount, CacheMode.AllowDownload);

                await messages.ForEachAwaitAsync(m =>
                {
                    foreach (var item in m)
                    {
                        file = file.Insert(0, $"{item.Author} ({item.Timestamp.UtcDateTime})\n\t{item.Content}\n\n");
                    }
                    return(Task.CompletedTask);
                });

                file = file.Insert(0, $"#{item.Name} at {now}\nBiscuit can only archive the last {MaxMessageCount} messages\n\n");

                await Utilities.SendTextAsFile(parameters.SocketMessage.Channel, file, $"{item.Name}.txt");
            }

            isTyping.Dispose();
        }
        public async Task Unmute(CommandParameters parameters)
        {
            var users = parameters.SocketMessage.MentionedUsers;
            var guild = await Android.Client.Rest.GetGuildAsync(Android.GuildID);

            if (users == null || users.Count == 0)
            {
                await parameters.Reply("no users specified");

                return;
            }

            foreach (var user in users)
            {
                var gU = await guild.GetUserAsync(user.Id);

                await Android.Moderation.Unmute(gU);
            }
        }
Esempio n. 11
0
 public async Task Lego(CommandParameters parameters)
 {
     await parameters.Reply("https://i.imgur.com/YsUVChu.png");
 }
Esempio n. 12
0
 public async Task DissmissingResponse(CommandParameters parameters)
 {
     await parameters.Reply("ok");
 }