public static async Task ClearSuggestions(CommandParameters parameters)
        {
            int newMaxSize = 1000;

            if (parameters.Arguments.Length > 0)
            {
                if (int.TryParse(parameters.Arguments[0], out var i))
                {
                    newMaxSize = i;
                }
            }

            var listener = parameters.Android.GetListener <SuggestionListener>();
            int size     = listener.Suggestions.Count;
            await parameters.SocketMessage.Channel.SendMessageAsync($"going through {size} entries...");

            await listener.GlobalRefresh(parameters.Android, newMaxSize);

            await parameters.SocketMessage.Channel.SendMessageAsync($"cleared {size} suggestions, new list has {listener.Suggestions.Count} entries");
        }
Beispiel #2
0
        public static async Task Define(CommandParameters parameters)
        {
            //https://github.com/meetDeveloper/googleDictionaryAPI
            const string api      = @"https://api.dictionaryapi.dev/api/v1/entries/en/";
            var          isTyping = parameters.SocketMessage.Channel.EnterTypingState();
            var          message  = parameters.SocketMessage.Content;
            var          word     = string.Join(" ", parameters.Arguments);

            try
            {
                var resultArray = await Utils.HttpGet <DictionaryApiResponse[]>(api + word);

                if (resultArray == null || resultArray.Length == 0)
                {
                    await parameters.SocketMessage.Channel.SendMessageAsync("i don't know");

                    isTyping?.Dispose();
                    return;
                }
                var result = resultArray[0];
                if (result.meaning == null || result.meaning.Count == 0)
                {
                    await parameters.SocketMessage.Channel.SendMessageAsync("i don't know");

                    isTyping?.Dispose();
                    return;
                }
                var reply = $@"**{result.word}**: {result.meaning.First().Value.First().definition}";
                isTyping?.Dispose();
                await parameters.SocketMessage.Channel.SendMessageAsync(reply);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + "\nwhile trying to get definition of \'" + word + "\'");
                isTyping?.Dispose();
                await parameters.SocketMessage.Channel.SendMessageAsync("i don't know");

                return;
            }
            isTyping?.Dispose();
        }
        private async Task Execute(string content, SocketMessage message, Android android)
        {
            foreach (var remoteResponse in remoteResponseTable)
            {
                if (remoteResponse.Key.ToLower() != content.ToLower())
                {
                    continue;
                }
                await message.Channel.SendMessageAsync(remoteResponse.Value);
            }

            foreach (CommandReference commandReference in commands)
            {
                foreach (string alias in commandReference.Aliases)
                {
                    if (!content.StartsWith(alias))
                    {
                        continue;
                    }
                    content = content.Remove(0, alias.Length).Trim();

                    string[] parts     = content.Split(' ').Where(e => !string.IsNullOrWhiteSpace(e)).ToArray();
                    string[] arguments = parts.ToArray();

                    CommandParameters parameters = new CommandParameters(message, android, arguments);

                    if (!commandReference.IsAuthorised(message.Channel.Id, message.Author.Id, parameters.Android.MainGuild.GetUser(message.Author.Id).Roles))
                    {
                        continue;
                    }
                    await(commandReference.Delegate(parameters) as Task);

                    break;
                }
            }

            await Task.CompletedTask;
        }
        private static async Task ParseAndMute(CommandParameters parameters, bool muted, TimeSpan duration = default)
        {
            var relevantUsers = parameters.SocketMessage.MentionedUsers;

            if (!relevantUsers.Any())
            {
                await parameters.SocketMessage.Channel.SendMessageAsync(DebugResponseConfiguration.Current.NoUserSpecifiedResponse.PickRandom());

                return;
            }

            foreach (SocketGuildUser user in relevantUsers)
            {
                if (muted)
                {
                    await MuteSystem.Mute(user.Id, parameters.SocketMessage.Channel.Id, duration);
                }
                else
                {
                    await MuteSystem.Unmute(user.Id);
                }
            }
        }
        public static async Task Compare(CommandParameters parameters)
        {
            var levenshtein = new F23.StringSimilarity.NormalizedLevenshtein();
            var adverbs     = new HashSet <string>(await File.ReadAllLinesAsync("all-adverbs.txt"));

            var A = GetSignificantContent(parameters.Arguments[0]);
            var B = GetSignificantContent(parameters.Arguments[1]);

            var duplicate = (A == B) || levenshtein.Distance(A, B) < .25f;

            await parameters.SocketMessage.Channel.SendMessageAsync($"{A}≈{B}={duplicate}");

            string GetSignificantContent(string content)
            {
                string lower = " " + content.Normalize().ToLower() + " ";

                foreach (var adverb in adverbs)
                {
                    lower = lower.Replace(" " + adverb + " ", " ");
                }

                return(lower.Trim());
            }
        }
Beispiel #6
0
 public static async Task ZooiBestFriend(CommandParameters parameters)
 {
     await parameters.SocketMessage.Channel.SendMessageAsync("vincent");
 }
Beispiel #7
0
 public static async Task BestFriend(CommandParameters parameters)
 {
     await parameters.SocketMessage.Channel.SendMessageAsync(parameters.SocketMessage.Author.Id == Server.Users.Koof? "you of course, silly <3 also you're short and gay" : "i don't know but it's definitely not you");
 }
Beispiel #8
0
 public static async Task Roadmap(CommandParameters parameters)
 {
     await parameters.SocketMessage.Channel.SendMessageAsync(DebugResponseConfiguration.Current.RoadmapLink);
 }
Beispiel #9
0
 public static async Task Love(CommandParameters parameters)
 {
     await parameters.SocketMessage.Channel.SendMessageAsync("<3");
 }
 public static async Task Unmute(CommandParameters parameters)
 {
     await ParseAndMute(parameters, false);
 }
 public static async Task Unlock(CommandParameters parameters)
 {
     await RemoveRole(parameters.SocketMessage, Server.Roles.Clown);
 }
        public static async Task Play(CommandParameters parameters)
        {
            var activityType = ActivityType.Playing;

            await SetStatus(parameters, activityType);
        }
 public static async Task Release(CommandParameters parameters)
 {
     await RemoveRole(parameters.SocketMessage, Server.Roles.Cowboy);
 }
        public static async Task TopSuggestions(CommandParameters parameters)
        {
            const int MaxSuggestionCount = 25;

            if (!int.TryParse(parameters.Arguments[0], out int count))
            {
                return;
            }
            Order order = Order.Best;

            switch (parameters.Arguments[1])
            {
            case "worst":
                order = Order.Worst;
                if (!parameters.Arguments[2].StartsWith("suggestion"))
                {
                    return;
                }
                break;

            case "best":
                order = Order.Best;
                if (!parameters.Arguments[2].StartsWith("suggestion"))
                {
                    return;
                }
                break;

            case "suggestions":
                order = Order.Best;
                break;

            case "suggestion":
                order = Order.Best;
                break;

            default: return;
            }

            if (count <= 0)
            {
                await parameters.SocketMessage.Channel.SendMessageAsync($"{count} isn't a valid amount. it has to be equal or more than 1");

                return;
            }

            var suggestions = parameters.Android.GetListener <SuggestionListener>().Suggestions;

            if (count > Math.Min(suggestions.Count, MaxSuggestionCount))
            {
                count = Math.Min(suggestions.Count, MaxSuggestionCount);
                await parameters.SocketMessage.Channel.SendMessageAsync($"i can only show {MaxSuggestionCount} entries");
            }

            var values = suggestions.Values;
            IEnumerable <SuggestionListener.Suggestion> topSuggestions;

            if (order == Order.Worst)
            {
                topSuggestions = values.OrderBy(s => s.Score).Take(count);
            }
            else
            {
                topSuggestions = values.OrderByDescending(s => s.Score).Take(count);
            }

            var builder = new EmbedBuilder();

            builder.Color = new Color(0x7289da);
            int index = 0;

            foreach (var suggestion in topSuggestions)
            {
                index++;
                builder.AddField($"#{index}: {suggestion.Score} points", suggestion.EllipsedContent);
            }
            var embed = builder.Build();

            await parameters.SocketMessage.Channel.SendMessageAsync($"the top {count} {order.ToString().ToLower()} suggestions are", false, embed);
        }
 public static async Task Nothing(CommandParameters parameters)
 {
     await parameters.SocketMessage.Channel.SendMessageAsync("ok");
 }
 public static async Task SuggestionPurge(CommandParameters parameters)
 {
     await parameters.Android.GetListener <SuggestionListener>().ResetPeriodicBoard();
 }
 public static async Task Untech(CommandParameters parameters)
 {
     await RemoveRole(parameters.SocketMessage, Server.Roles.TechBan);
 }
 public static async Task Unban(CommandParameters parameters)
 {
     await SetChannelBan(parameters.SocketMessage, false);
 }
Beispiel #19
0
 public static async Task Atst(CommandParameters parameters)
 {
     await parameters.SocketMessage.Channel.SendFileAsync(Android.Path + "atst.png");
 }
        public static async Task Listen(CommandParameters parameters)
        {
            var activityType = ActivityType.Listening;

            await SetStatus(parameters, activityType);
        }
        public static async Task Quit(CommandParameters parameters)
        {
            await parameters.SocketMessage.Channel.SendMessageAsync("goodbye");

            await parameters.Android.Shutdown();
        }
 public static async Task Interrogate(CommandParameters parameters)
 {
     await SetRole(parameters.SocketMessage, Server.Roles.Cowboy);
 }
 public static async Task Hi(CommandParameters parameters)
 {
     await parameters.SocketMessage.Channel.SendMessageAsync(DebugResponseConfiguration.Current.GreetingResponses.PickRandom());
 }
 public static async Task CleanMods(CommandParameters parameters)
 {
     CrudeModdingStorage.Current = new CrudeModdingStorage();
     await parameters.Android.GetListener <CrudeModListener>().SaveToDisk();
 }
        public static async Task Watch(CommandParameters parameters)
        {
            var activityType = ActivityType.Watching;

            await SetStatus(parameters, activityType);
        }
 public static async Task Violations(CommandParameters parameters)
 {
     await parameters.SocketMessage.Channel.SendMessageAsync(string.Join("\n", parameters.Android.GetListener <ViolationListener>().Violations));
 }
        public static async Task Archive(CommandParameters parameters)
        {
            const int MaxMessageCount = 10000;

            Regex regex   = new Regex(@"(<#\d+>)");
            var   matches = regex.Matches(parameters.SocketMessage.Content);
            await parameters.SocketMessage.Channel.SendMessageAsync($"okay! working on it");

            var files = new List <ChannelArchive>();

            if (matches.Count == 0)
            {
                await addToFiles(parameters.SocketMessage.Channel);
            }

            foreach (Match match in matches)
            {
                bool successfulParse = ulong.TryParse(new string(match.Value.Where(c => char.IsDigit(c)).ToArray()), out var channelId);
                if (!successfulParse)
                {
                    continue;
                }
                var channel = parameters.Android.Client.GetChannel(channelId);
                if (channel == null)
                {
                    continue;
                }
                try
                {
                    IMessageChannel tc = (IMessageChannel)channel;
                    await addToFiles(tc);
                }
                catch (Exception)
                {
                    Console.WriteLine(channel.Id + " is not a text channel");
                }
            }

            foreach (var archive in files)
            {
                await Utils.SendTextAsFile(parameters.SocketMessage.Channel, archive.Data, $"{archive.Name}.txt");
            }

            async Task addToFiles(IMessageChannel tc)
            {
                var    messages = tc.GetMessagesAsync(limit: MaxMessageCount, mode: CacheMode.AllowDownload);
                string file     = "";
                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, $"#{tc.Name} at {DateTime.UtcNow}\nBiscuit can only archive the last {MaxMessageCount} messages\n\n");

                files.Add(new ChannelArchive(tc.Name, file));
            }
        }
 public static async Task Silence(CommandParameters parameters)
 {
     await Mute(parameters);
 }