Пример #1
0
        public async void ProcessWinner(string winner, int gameID)
        {
            match.Winners.GetRecordData(out var first, out var record);
            if (first.Wins == 2 && HostRun != null && LeagueRunOpp != null)
            {
                var WinningRun = HostRun.Person.Equals(winner, StringComparison.InvariantCultureIgnoreCase) ? HostRun : LeagueRunOpp;
                var LosingRun  = (new DecksiteApi.Deck[] { HostRun, LeagueRunOpp }).Single(d => d != WinningRun);
                if (Features.PublishResults && await DecksiteApi.UploadResultsAsync(WinningRun, LosingRun, record, match.MatchID))
                {
                    await DiscordService.SendToLeagueAsync($":trophy: {WinningRun.Person} {record} {LosingRun.Person}");
                }
                else
                {
                    try
                    {
                        var winnerMention = await DiscordFunctions.MentionOrElseNameAsync(WinningRun.Person);

                        var losingMention = await DiscordFunctions.MentionOrElseNameAsync(LosingRun.Person);

                        await DiscordService.SendToLeagueAsync($":trophy: {winnerMention} {record} {losingMention} (Please verify and report manually)");
                    }
                    catch (Exception c)
                    {
                        await DiscordService.SendToLeagueAsync($":trophy: {WinningRun.Person} {record} {LosingRun.Person} (Please verify and report manually)");

                        Console.WriteLine(c);
                        await DiscordService.SendToTestAsync(c.ToString());
                    }
                }
            }
        }
Пример #2
0
        public static async System.Threading.Tasks.Task <bool> MusicCommands(SocketMessage message, CommandContext context, DiscordSocketClient client, LavaNode lava)
        {
            if (Validation.CheckCommand(message, "play"))
            {
                if ((message.Author as IVoiceState).VoiceChannel == null)
                {
                    DiscordFunctions.EmbedThis("Music", "You must first join a voice channel!", "red", context);
                    return(true);
                }


                var temp = client.GetGuild(context.Guild.Id).CurrentUser.VoiceState;
                if (temp != null && client.GetGuild(context.Guild.Id).CurrentUser.VoiceChannel != (message.Author as IVoiceState).VoiceChannel)
                {
                    DiscordFunctions.EmbedThis("Music", "I can't join another voice channel until I'm disconnected from another channel.", "red", context);
                    return(true);
                }

                SearchResponse search    = new SearchResponse();
                var            videoId   = string.Empty;
                var            timestamp = string.Empty;
                string         query     = message.Content.ToLower().Replace("!play ", "");
                if (query.ToLower().Contains("www.youtube.com/watch?v="))
                {
                    var uri     = new Uri(@query);
                    var queryid = HttpUtility.ParseQueryString(uri.Query);

                    if (queryid.AllKeys.Contains("v"))
                    {
                        videoId = queryid["v"];
                    }
                    else
                    {
                        videoId = uri.Segments.Last();
                    }
                    if (queryid.AllKeys.Contains("t"))
                    {
                        timestamp = queryid["t"];
                    }
                    if (timestamp != string.Empty)
                    {
                        videoId = videoId.Replace("&t=" + timestamp, "");
                    }
                    search = await lava.SearchYouTubeAsync(query.Replace("&t=" + timestamp, ""));
                }
                else
                {
                    search = await lava.SearchYouTubeAsync(query);
                }
                LavaTrack track = new LavaTrack();
                if (query.ToLower().Contains("www.youtube.com/watch?v="))
                {
                    bool found = false;
                    foreach (var vid in search.Tracks)
                    {
                        if (vid.Id.ToLower() == videoId)
                        {
                            track = vid;
                            found = true;
                            break;
                        }
                    }
                    if (found == false)
                    {
                        track = search.Tracks.FirstOrDefault();
                    }
                }
                else
                {
                    track = search.Tracks.FirstOrDefault();
                }

                var player = lava.HasPlayer(context.Guild)
                    ? lava.GetPlayer(context.Guild)
                    : await lava.JoinAsync((context.User as IVoiceState).VoiceChannel, (ITextChannel)message.Channel);

                if (player.PlayerState == PlayerState.Playing)
                {
                    player.Queue.Enqueue(track);
                    DiscordFunctions.EmbedThis("Music", "Enqeued " + track.Title, "orange", context);
                }
                else
                {
                    await player.PlayAsync(track);

                    try
                    {
                        if (timestamp != string.Empty)
                        {
                            if (timestamp.ToLower().Contains("s"))
                            {
                                timestamp = timestamp.ToLower().Replace("s", "");
                            }
                            await player.SeekAsync(TimeSpan.FromSeconds(Convert.ToDouble(timestamp)));
                        }
                    }
                    catch { }
                    DiscordFunctions.EmbedThis("Music", "Playing " + track.Title, "green", context);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "skip"))
            {
                var _player = lava.GetPlayer(context.Guild);
                if (_player is null || _player.Queue.Count is 0)
                {
                    DiscordFunctions.EmbedThis("Music", "Nothing in the queue", "orange", context);
                    return(true);
                }

                var oldTrack = _player.Track;
                await _player.SkipAsync();

                DiscordFunctions.EmbedThis("Music", "Skipped: " + oldTrack.Title + "\nNow Playing: " + _player.Track.Title, "orange", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "stop"))
            {
                var _player = lava.GetPlayer(context.Guild);
                if (_player == null)
                {
                    return(true);
                }

                await _player.StopAsync();

                DiscordFunctions.EmbedThis("Music", "Stopped player", "orange", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "volume"))
            {
                LavaPlayer _player;
                try
                {
                    _player = lava.GetPlayer(context.Guild);
                }
                catch
                {
                    DiscordFunctions.EmbedThis("Music", "Nothing is playing", "orange", context);
                    return(true);
                }
                if (string.IsNullOrWhiteSpace(message.Content.Replace("!volume", "")))
                {
                    DiscordFunctions.EmbedThis("Music", "Please use a number between 2- 150", "orange", context);
                    return(true);
                }
                var vol = Convert.ToUInt16(message.Content.Replace("!volume", "").Trim());
                if (vol > 150 || vol <= 2)
                {
                    DiscordFunctions.EmbedThis("Music", "Please use a number between 2- 150", "orange", context);
                    return(true);
                }

                await _player.UpdateVolumeAsync(vol);

                DiscordFunctions.EmbedThis("Music", "Volume set to: " + vol.ToString(), "green", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "pause"))
            {
                LavaPlayer _player;
                try
                {
                    _player = lava.GetPlayer(context.Guild);
                }
                catch
                {
                    DiscordFunctions.EmbedThis("Music", "Nothing is playing", "orange", context);
                    return(true);
                }
                if (_player.PlayerState != PlayerState.Paused)
                {
                    await _player.PauseAsync();

                    DiscordFunctions.EmbedThis("Music", "Player is Paused", "orange", context);
                    return(true);
                }
                else
                {
                    await _player.ResumeAsync();

                    DiscordFunctions.EmbedThis("Music", "Playback Resumed", "green", context);
                    return(true);
                }
            }
            else if (Validation.CheckCommand(message, "resume"))
            {
                LavaPlayer _player;
                try
                {
                    _player = lava.GetPlayer(context.Guild);
                }
                catch
                {
                    DiscordFunctions.EmbedThis("Music", "Nothing is playing", "orange", context);
                    return(true);
                }
                if (_player.PlayerState != PlayerState.Paused)
                {
                    await _player.ResumeAsync();

                    DiscordFunctions.EmbedThis("Music", "Playback Resumed", "green", context);
                    return(true);
                }
                else
                {
                    DiscordFunctions.EmbedThis("Music", "Playback is not paused", "orange", context);
                    return(true);
                }
            }
            else if (Validation.CheckCommand(message, "join"))
            {
                var user = context.User as SocketGuildUser;
                if (user.VoiceChannel is null)
                {
                    DiscordFunctions.EmbedThis("Music", "You need to connect to a voice channel", "red", context);
                    return(true);
                }
                else
                {
                    LavaPlayer _player;
                    try
                    {
                        _player = lava.GetPlayer(context.Guild);
                        DiscordFunctions.EmbedThis("Music", "Bot is already in a channel", "red", context);
                        return(true);
                    }
                    catch
                    {
                        await lava.JoinAsync((context.User as IVoiceState).VoiceChannel, (ITextChannel)message.Channel);

                        return(true);
                    }
                }
            }
            else if (Validation.CheckCommand(message, "leave"))
            {
                var user = context.User as SocketGuildUser;
                if (user.VoiceChannel is null)
                {
                    DiscordFunctions.EmbedThis("Music", "Please join the channel the bot is in to make it leave", "red", context);
                    return(true);
                }
                else
                {
                    LavaPlayer _player;
                    try
                    {
                        _player = lava.GetPlayer(context.Guild);
                    }
                    catch
                    {
                        DiscordFunctions.EmbedThis("Music", "Please join the channel the bot is in to make it leave", "red", context);
                        return(true);
                    }
                    if (_player.VoiceChannel == user.VoiceChannel)
                    {
                        await lava.LeaveAsync((context.User as IVoiceState).VoiceChannel);
                    }
                    else
                    {
                        DiscordFunctions.EmbedThis("Music", "Please join the channel the bot is in to make it leave", "red", context);
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #3
0
        public static async Task <bool> FunCommands(SocketMessage message, CommandContext context, DiscordSocketClient client)
        {
            if (Validation.CheckCommand(message, "wednesday"))
            {
                string source = "https://i.imgur.com/2SRddtz.jpg";
                string desc   = "***It is Wednesday,***\n" + "***my dudes***\n";
                DiscordFunctions.EmbedThisImage("Wednesday", desc, source, "magenta", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "ficus"))
            {
                string source = "https://pbs.twimg.com/profile_images/884098118907699200/i8L4V-es_400x400.jpg";
                string desc   = "";
                DiscordFunctions.EmbedThisImage("Praise be", desc, source, "magenta", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "8ball"))
            {
                string user = message.Author.Username;

                if (string.IsNullOrWhiteSpace(message.Content.Replace("!8ball", "")))
                {
                    throw new ArgumentException(user + " 🎱 Please enter a question to ask 8ball" + "\n **Command Usage: **.8ball <question> ");
                }

                Random rand  = new Random();
                int    value = rand.Next(0, 7);

                string response = "";
                switch (value)
                {
                case 0:
                    response = "Yeah";
                    break;

                case 1:
                    response = "100% dude";
                    break;

                case 2:
                    response = "Probably lol";
                    break;

                case 3:
                    response = "lmao, why??";
                    break;

                case 4:
                    response = "Nope";
                    break;

                case 5:
                    response = "Nah, I doubt it tbh";
                    break;

                case 6:
                    response = "Absolutely not";
                    break;
                }

                string title       = "🎱 Magic 8 Ball 🎱";
                string description = $"**Question:** {message.Content.Replace("!8ball", "")}\n**Asked by: **{user}\n**Answer:** {response}";

                DiscordFunctions.EmbedThis(title, description, "", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "flip") || Validation.CheckCommand(message, "coin"))
            {
                await context.Channel.SendMessageAsync("*Flipping a coin...* ⚖️");

                Random rand   = new Random();
                int    result = rand.Next(0, 2);
                string user   = context.User.Mention;

                await Task.Delay(1000);

                if (result == 0)
                {
                    await context.Channel.SendMessageAsync(user + "*, it's tails!*");
                }
                else
                {
                    await context.Channel.SendMessageAsync(user + "*, it's heads!*");
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "cat"))
            {
                using (var webclient = new HttpClient())
                {
                    webclient.Timeout = TimeSpan.FromSeconds(2);
                    var s = await webclient.GetStringAsync("http://aws.random.cat/meow");

                    var json = JsonConvert.DeserializeObject <CatDog>(s);
                    await context.Channel.SendMessageAsync(json.File);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "catfact"))
            {
                using (var webclient = new HttpClient())
                {
                    webclient.Timeout = TimeSpan.FromSeconds(2);
                    var s = await webclient.GetStringAsync("https://catfact.ninja/fact");

                    var json = JsonConvert.DeserializeObject <CatFact>(s);
                    await context.Channel.SendMessageAsync(json.Fact);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "dog"))
            {
                using (var webclient = new HttpClient())
                {
                    webclient.Timeout = TimeSpan.FromSeconds(2);
                    var dog = "http://random.dog/" + await webclient.GetStringAsync("http://random.dog/woof");

                    await context.Channel.SendMessageAsync(dog);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "info"))
            {
                var application = await context.Client.GetApplicationInfoAsync();

                EmbedBuilder eb  = new EmbedBuilder();
                IGuildUser   bot = await context.Guild.GetCurrentUserAsync();

                eb.Author       = new EmbedAuthorBuilder().WithName(bot.Nickname ?? bot.Username).WithIconUrl(context.Client.CurrentUser.GetAvatarUrl());
                eb.ThumbnailUrl = context.Client.CurrentUser.GetAvatarUrl();
                eb.Color        = Color.Green;
                eb.Description  = $"{Format.Bold("Info")}\n" +
                                  $"- Author: {application.Owner.Username} (ID {application.Owner.Id})\n" +
                                  $"- Library: Discord.Net ({DiscordConfig.Version})\n" +
                                  $"- Runtime: {RuntimeInformation.FrameworkDescription} {RuntimeInformation.OSArchitecture}\n" +
                                  $"- Uptime: {(DateTime.Now - Process.GetCurrentProcess().StartTime).ToString(@"dd\.hh\:mm\:ss")}\n\n" +

                                  $"{Format.Bold("Stats")}\n" +
                                  $"- Heap Size: {Math.Round(GC.GetTotalMemory(true) / (1024.0 * 1024.0), 2).ToString()} MB\n" +
                                  $"- Guilds: {(context.Client as DiscordSocketClient).Guilds.Count}\n" +
                                  $"- Channels: {(context.Client as DiscordSocketClient).Guilds.Sum(g => g.Channels.Count)}\n" +
                                  $"- Users: {(context.Client as DiscordSocketClient).Guilds.Sum(g => g.Users.Count)}";
                await context.Channel.SendMessageAsync("", false, eb.Build());

                return(true);
            }
            else if (Validation.CheckCommand(message, "ping"))
            {
                DiscordFunctions.EmbedThis("Pong", "Status: " + client.Status + "\nResponse Time: " + client.Latency + "ms", "", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "nihilism"))
            {
                await context.Channel.SendMessageAsync(context.User.Mention + $" You get nothing");

                return(true);
            }
            else if (Validation.CheckCommand(message, "whoami"))
            {
                await context.Channel.SendMessageAsync(context.User.Mention + $" You are: " + message.Author.Username + "#" + message.Author.Discriminator.ToString());

                return(true);
            }
            else if (Validation.CheckCommand(message, "excuse"))
            {
                DiscordFunctions.EmbedThis("", Angela.RandomExcuse(), "", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "pun"))
            {
                DiscordFunctions.EmbedThis("", Angela.RandomPun(), "", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "roll"))
            {
                if (Validation.WordCountEqual(message, 2))
                {
                    var isNumeric = int.TryParse(DiscordFunctions.GetWord(message, 1), out int n);
                    if (isNumeric == true)
                    {
                        DiscordFunctions.EmbedThis("Rolled", Angela.Roll(Int32.Parse(DiscordFunctions.GetWord(message, 1))).ToString(), "", context);
                    }
                    else
                    {
                        DiscordFunctions.EmbedThis("", "That is not a number", "", context);
                    }
                }
                else
                {
                    // Warn the user it was a bad command
                    DiscordFunctions.EmbedThis("Incomplete Command", "!roll number", "", context);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "nuggets"))
            {
                if (Validation.WordCountEqual(message, 2))
                {
                    var isNumeric = int.TryParse(DiscordFunctions.GetWord(message, 1), out int n);
                    if (isNumeric == true)
                    {
                        DiscordFunctions.EmbedThis("Nugget Conversion", message.Author.Mention + " $" + DiscordFunctions.GetWord(message, 1) + " is equal to " + Angela.Nuggets(Int32.Parse(DiscordFunctions.GetWord(message, 1))) + " chicken nuggets", "", context);
                    }
                    else
                    {
                        DiscordFunctions.EmbedThis("", "That is not a number", "", context);
                    }
                }
                else
                {
                    // Warn the user it was a bad command
                    DiscordFunctions.EmbedThis("Incomplete Command", "!nuggets number", "", context);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "rate"))
            {
                int random = new Random().Next(12);
                if (random == 11)
                {
                    random = new Random().Next(12);
                }
                await context.Channel.SendMessageAsync(context.User.Mention + $" 🤔 I would rate that a " + random.ToString() + "/10");

                return(true);
            }
            else if (Validation.CheckCommand(message, "xkcd"))
            {
                string xkcdUrl  = $"http://xkcd.com/";
                Random rand     = new Random();
                Uri    uri      = new Uri($"{xkcdUrl}{rand.Next(1, 2246)}/info.0.json");
                var    response = await new ApiHandler <XKCD>().GetJSONAsync(uri);
                if (response?.Url != null)
                {
                    await context.Channel.SendMessageAsync(response.Title + ": " + response.Url);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "points"))
            {
                using (var db = new LiteDatabase(@"Points.db"))
                {
                    try
                    {
                        var Points = db.GetCollection <Points>("Points");
                        if (Validation.WordCountEqual(message, 3))
                        {
                            if (Validation.IsHGorAdmin(message, client))
                            {
                                if (DiscordFunctions.GetWord(message, 1).ToLower() == "add")
                                {
                                    Points point = new Points
                                    {
                                        PointsNumber = 0,
                                        PointTitle   = DiscordFunctions.GetWord(message, 2)
                                    };
                                    Points.Insert(point);
                                    DiscordFunctions.EmbedThis(point.PointTitle, "Was added to the points database", "", context);
                                }
                                else if (DiscordFunctions.GetWord(message, 1).ToLower() == "delete")
                                {
                                    var result = Points.FindOne(x => x.PointTitle.StartsWith(DiscordFunctions.GetWord(message, 2)));
                                    Points.Delete(result.Id);
                                    DiscordFunctions.EmbedThis(DiscordFunctions.GetWord(message, 2), "Was removed from the points database", "", context);
                                }
                            }
                        }
                        else if (Validation.WordCountEqual(message, 4))
                        {
                            if (DiscordFunctions.GetWord(message, 1).ToLower() == "modify")
                            {
                                if (Validation.IsHGorAdmin(message, client))
                                {
                                    var result = Points.FindOne(x => x.PointTitle.StartsWith(DiscordFunctions.GetWord(message, 2)));
                                    result.PointsNumber = result.PointsNumber + Convert.ToDouble(DiscordFunctions.GetWord(message, 3));
                                    Points.Update(result);
                                    DiscordFunctions.EmbedThis(result.PointTitle, "Current points are now: " + result.PointsNumber, "", context);
                                }
                            }
                        }
                        else
                        {
                            var results   = Points.FindAll();
                            var pointlist = "";
                            foreach (Points point in results)
                            {
                                pointlist = pointlist + '\t' + '\t' + '\t' + point.PointTitle + ": " + point.PointsNumber + '\n';
                            }
                            DiscordFunctions.EmbedThis("-------------------Points-------------------", pointlist, "", context);
                        }
                    }
                    catch { }
                }
                return(true);
            }
            return(false);
        }
Пример #4
0
        public static async System.Threading.Tasks.Task <bool> HelpCommands(SocketMessage message, CommandContext context)
        {
            var generalHelp = new EmbedBuilder();

            generalHelp.WithTitle("Angela Commands");
            generalHelp.WithDescription("Text:");
            generalHelp.AddField("Help", "Shows this command");
            generalHelp.AddField("Excuse", "Shows an excuse");
            generalHelp.AddField("Pun", "Shows a Pun");
            generalHelp.AddField("Roll <x>", "Allows you to roll a number");
            generalHelp.AddField("Flip", "Flips a coin");
            generalHelp.AddField("Wednesday", "It's Wednesday my dudes");
            generalHelp.AddField("Cat", "Shows a random picture of a cat");
            generalHelp.AddField("Dog", "Shows a random picture of a dog");
            generalHelp.AddField("Ping", "Pong");
            generalHelp.AddField("Info", "Tells you stats about the bot");
            generalHelp.AddField("Rate <info>", "Asks Angela to rate something on a scale from 1-10");
            generalHelp.AddField("Nuggets <x>", "Allows you to convert $ to chicken nuggets");
            generalHelp.AddField("Points", "Shows the current point standings");
            generalHelp.AddField("Ficus", "Praise be the ficus");
            generalHelp.AddField("XKCD", "Returns you a random XKCD comic");
            generalHelp.AddField("SMS", "Enables or Disables SMS notifications");
            generalHelp.AddField("Notify <channel>", "Enables notifications for a specific channel (No entry will set it to the channel you are in)");
            generalHelp.AddField("WhoAmI", "Replies with your full discord ID");
            generalHelp.AddField("Nihilism", "You get nothing");
            generalHelp.AddField("CatFact", "Subscribes you to catfacts");
            generalHelp.WithFooter("Page 1/5");

            generalHelp.WithThumbnailUrl("https://i.imgur.com/FmAdIKq.png");
            generalHelp.WithColor(Color.Blue);

            var musicHelp = new EmbedBuilder();

            musicHelp.WithTitle("Angela Commands");
            musicHelp.WithDescription("Music:");
            musicHelp.AddField("Play <song>", "Plays a song from youtube in voice chat");
            musicHelp.AddField("Skip", "Skips the current playing song");
            musicHelp.AddField("Stop", "Stops playing music");
            musicHelp.AddField("Volume <2-150>", "Sets the music volume");
            musicHelp.AddField("Pause", "Pauses the current song");
            musicHelp.AddField("Resume", "Resumes the current song");
            musicHelp.AddField("Join", "Joins Angela to your voice channel");
            musicHelp.AddField("Leave", "Leaves the current voice channel");
            musicHelp.WithFooter("Page 2/5");

            musicHelp.WithThumbnailUrl("https://i.imgur.com/FmAdIKq.png");
            musicHelp.WithColor(Color.Blue);


            var landingHelp = new EmbedBuilder();

            landingHelp.WithTitle("Angela Commands");
            landingHelp.WithDescription("Landing:");
            landingHelp.AddField("Guardian", "Attempts to authenticate you as a Guardian");
            landingHelp.AddField("RtxLondon", "Attempts to authenticate you as an RTX London Guardian");
            landingHelp.WithFooter("Page 3/5");

            landingHelp.WithThumbnailUrl("https://i.imgur.com/FmAdIKq.png");
            landingHelp.WithColor(Color.Teal);

            var teamleadHelp = new EmbedBuilder();

            teamleadHelp.WithTitle("Angela Commands");
            teamleadHelp.WithDescription("Team Lead:");
            teamleadHelp.AddField("Squadlead <@user>", "Makes a user a squad lead (Must be run in a channel you can @ them)");
            teamleadHelp.AddField("Squad <@user> <squad>", "Adds a user to a squad (Must be run in a channel you can @ them)");
            teamleadHelp.AddField("Addchannel <channelname> <description>", "Creates a channel with a description under your team");
            teamleadHelp.AddField("Deletechannel <channelname>", "Deletes a channel under your team");
            teamleadHelp.WithFooter("Page 4/5");

            teamleadHelp.WithThumbnailUrl("https://i.imgur.com/FmAdIKq.png");
            teamleadHelp.WithColor(Color.Purple);


            var adminHelp = new EmbedBuilder();

            adminHelp.WithTitle("Angela Commands");
            adminHelp.WithDescription("Admin:");
            adminHelp.AddField("Sweep <x>", "Clears x messages");
            adminHelp.AddField("Impersonate <message>", "Allows you to impersonate Angela");
            adminHelp.AddField("Updaterules", "Forces the rules page to update");
            adminHelp.AddField("Giant", "Fee-Fi-Fo");
            adminHelp.AddField("Everyone <true/false>", "Updates if the tweet bot has the everyone tag");
            adminHelp.AddField("Tweetchannel <#channel>", "Specifies the channel to send tweets to");
            adminHelp.AddField("Debuglist", "Prints information about Events/Broken info to Console");
            adminHelp.AddField("Reload", "Reloads user database information");
            adminHelp.AddField("Withdraw <username#discriminator>", "Withdraws a user as a guardian from that event");
            adminHelp.AddField("Newevent <event> <year>", "Creates a new event with the year and info");
            adminHelp.AddField("Deleteevent <event> <year>", "Deletes a previous years event specific info and saves the bar");
            adminHelp.AddField("Points <add/delete/modify> <pointset> <number>", "Allows you to manage points (Add creates a new set, Delete removes a set, modify changes points), pointset and number are only used for modify");
            adminHelp.AddField("Unauthenticated", "Prints out the list of users that have not authenticated for the event");
            adminHelp.AddField("ClearDB", "Clears the DB of unauthenticated users, suggest doing a reload after");

            adminHelp.WithFooter("Page 5/5");

            adminHelp.WithThumbnailUrl("https://i.imgur.com/FmAdIKq.png");
            adminHelp.WithColor(Color.Red);

            var casevar = "";

            try
            {
                casevar = DiscordFunctions.GetWord(message, 1);
            }
            catch { }
            switch (casevar)
            {
            case "1":
                await context.Channel.SendMessageAsync("", false, generalHelp.Build());

                break;

            case "2":
                await context.Channel.SendMessageAsync("", false, musicHelp.Build());

                break;

            case "3":
                await context.Channel.SendMessageAsync("", false, landingHelp.Build());

                break;

            case "4":
                await context.Channel.SendMessageAsync("", false, teamleadHelp.Build());

                break;

            case "5":
                await context.Channel.SendMessageAsync("", false, adminHelp.Build());

                break;

            case "all":
                await context.Channel.SendMessageAsync("", false, generalHelp.Build());

                await context.Channel.SendMessageAsync("", false, musicHelp.Build());

                await context.Channel.SendMessageAsync("", false, landingHelp.Build());

                await context.Channel.SendMessageAsync("", false, teamleadHelp.Build());

                await context.Channel.SendMessageAsync("", false, adminHelp.Build());

                break;

            default:
                if (message.Channel.Name.ToLower() == "landing")
                {
                    await context.Channel.SendMessageAsync("", false, landingHelp.Build());
                }
                else
                {
                    await context.Channel.SendMessageAsync("", false, generalHelp.Build());
                }
                break;
            }
            return(true);
        }
Пример #5
0
        private async Task PostPairingsAsync(Event eventModel, Round round)
        {
            if (!Features.AnnouncePairings)
            {
                return;
            }

            var room = eventModel.Channel;

            ulong?ChanId = null;

            if (eventModel.Series.Contains("Penny Dreadful"))
            {
                ChanId = 334220558159970304;
            }
            else if (eventModel.Series.Contains("7 Point"))
            {
                ChanId = 600281000739733514;
            }

            if (!ChanId.HasValue && (string.IsNullOrWhiteSpace(room) || string.IsNullOrWhiteSpace(room.Trim('#'))))
            {
                Console.WriteLine($"No MTGO room defined for {eventModel}.");
                return;
            }

            var builder = new StringBuilder();

            if (round.RoundNum == 1 && !round.IsFinals && !Features.PublishResults)
            {
                builder.AppendLine("[sF] Due to the spectator switcheroo bug, PDBot cannot trust the results it sees on screen.");
                builder.AppendLine("[sF] PDBot will not be reporting match results to the channel until this bug is fixed.");
                builder.AppendLine("[sF] If you spectate any other player's matches in the tournament," +
                                   " please keep in mind that player names could be attached to the wrong players.");
            }

            if (round.IsFinals && round.Matches.Count == 1)
            {
                builder.Append($"[sD] Pairings for Finals:\n");
            }
            else if (round.IsFinals)
            {
                builder.Append($"[sD] Pairings for Top {round.Matches.Count * 2}:\n");
            }
            else
            {
                builder.Append($"[sD] Pairings for Round {round.RoundNum}:\n");
            }
            var  misses = 0;
            bool isPD   = eventModel.Series.Contains("Penny Dreadful") && Features.ConnectToDiscord;

            foreach (var pairing in round.Matches)
            {
                if (pairing.A == pairing.B)
                {
                    builder.Append("[sG] ");
                }
                else if (pairing.Verification == "verified")
                {
                    misses += 1;
                    builder.Append("[sT] ");
                }
                else if (pairing.Verification == "unverified")
                {
                    builder.Append("[sR] ");
                }
                else if (pairing.Res == "vs.")
                {
                    builder.Append("[sR] ");
                }
                else
                {
                    misses += 1;
                    builder.Append("[sT] ");
                }
                if (ChanId.HasValue)
                {
                    pairing.CalculateRes();
                    var A = await DiscordFunctions.MentionOrElseNameAsync(pairing.A);

                    var B = await DiscordFunctions.MentionOrElseNameAsync(pairing.B);

                    if (pairing.Res == "BYE")
                    {
                        builder.Append($"{A} has the BYE!");
                    }
                    else
                    {
                        builder.Append($"{A} {pairing.Res} {B}");
                    }
                }
                else
                {
                    builder.Append(pairing.ToString());
                }
                builder.Append("\n");
            }
            if (!round.IsFinals && (isPD || misses == 0))
            {
                var minutes = FreeWinTime(eventModel.Name, round.RoundNum);
                builder.AppendLine($"[sB] No-Show win time: XX:{minutes.ToString("D2")}");
            }
            builder.Append("[sD] Good luck, everyone!");

            string doorPrize = null;

            if (ChanId.HasValue)
            {
                if (isPD && eventModel.Rounds.ContainsKey(round.RoundNum - 1))
                {
                    var prev = eventModel.Rounds[round.RoundNum - 1];
                    if (round.IsFinals && !prev.IsFinals && round.Players.Count() == 8)
                    {
                        var top8players = round.Players.ToArray();
                        var eligible    = prev.Players.Where(p => !top8players.Contains(p)).ToArray();
                        var winner      = await DiscordFunctions.MentionOrElseNameAsync(eligible[new Random().Next(eligible.Count())]);

                        doorPrize = $"[sEventTicket] And the Door Prize goes to...\n [sEventTicket] {winner} [sEventTicket]";
                    }
                }

                await DiscordFunctions.PostTournamentPairingsAsync(ChanId.Value, builder.ToString(), doorPrize);
            }
            else if (misses < 3)
            {
                var sent = Chat.SendPM(room, builder.ToString());
                if (!string.IsNullOrEmpty(doorPrize))
                {
                    Chat.SendPM(room, doorPrize);
                }
                if (!sent)
                {
                    Chat.Join(room);
                    await Task.Delay(TimeSpan.FromSeconds(10));
                    await PostPairingsAsync(eventModel, round);
                }
            }
            // If misses >= 3, we have clearly just rebooted.  Don't send anything.
        }
Пример #6
0
        public static async Task <bool> AdminCommands(SocketMessage message, CommandContext context, DiscordSocketClient client)
        {
            if (Validation.CheckCommand(message, "sweep"))
            {
                if (Validation.WordCountEqual(message, 2))
                {
                    try
                    {
                        int loops = 1;
                        try
                        {
                            loops = System.Convert.ToInt32(DiscordFunctions.GetWord(message, 1));
                        }
                        catch (FormatException)
                        {
                        }
                        await DiscordFunctions.DeleteLastMessage(context, message.Channel.ToString());

                        for (int i = 0; i < loops; i++)
                        {
                            await DiscordFunctions.DeleteLastMessage(context, message.Channel.ToString());

                            await Task.Delay(1000);
                        }
                        DiscordFunctions.EmbedThisImage("Sweep Sweep", "", "https://i.imgur.com/UH1MPDz.gif", "green", context);
                    }
                    catch { }
                }
                else
                {
                    // Warn the user it was a bad command
                    DiscordFunctions.EmbedThis("Incomplete Command", "!sweep #", "red", context);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "impersonate"))
            {
                // Make sure we have all parts
                if (Validation.WordCountGreater(message, 3))
                {
                    foreach (IGuildChannel channel in client.GetGuild(405513567681642517).TextChannels)
                    {
                        if (channel.Name == DiscordFunctions.GetWord(message, 1).Replace("#", ""))
                        {
                            string rebuiltstring = message.Content.Replace(DiscordFunctions.GetWord(message, 0) + " ", "").Replace(DiscordFunctions.GetWord(message, 1) + " ", "");
                            await client.GetGuild(405513567681642517).GetTextChannel(channel.Id).SendMessageAsync(rebuiltstring);

                            break;
                        }
                    }
                }
                else
                {
                    // Warn the user it was a bad command
                    DiscordFunctions.EmbedThis("Incomplete Command", "!impersonate #channel message", "red", context);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "deleteevent"))
            {
                // Make sure we have all parts
                if (Validation.WordCountEqual(message, 3))
                {
                    using (var db = new LiteDatabase(@"Events.db"))
                    {
                        try
                        {
                            var Events = db.GetCollection <Events>("Events");
                            var Event  = Events.FindOne(x => x.Event.StartsWith(DiscordFunctions.GetWord(message, 1) + "-" + DiscordFunctions.GetWord(message, 2)));
                            Events.Delete(Event.Id);
                        }
                        catch { }
                    }
                    // Send a message saying we sre starting
                    DiscordFunctions.EmbedThis("Event being deleted", message.Author.Mention + " deleting event " + DiscordFunctions.GetWord(message, 1) + "-" + DiscordFunctions.GetWord(message, 2), "orange", context);
                    await DiscordFunctions.CleanupEvent(context, message);

                    DiscordFunctions.EmbedThis("Deletion Complete", "Event Deleted " + DiscordFunctions.GetWord(message, 1) + "-" + DiscordFunctions.GetWord(message, 2), "green", context);
                }
                else
                {
                    // Warn the user it was a bad command
                    DiscordFunctions.EmbedThis("Incomplete Command", "!deleteevent EVENT YEAR", "red", context);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "updaterules"))
            {
                foreach (IGuildChannel channel in client.GetGuild(486327167035244554).TextChannels)
                {
                    if (channel.Name == "rules")
                    {
                        bool loop = true;
                        while (loop)
                        {
                            try
                            {
                                IEnumerable <IMessage> messages = await client.GetGuild(486327167035244554).GetTextChannel(channel.Id).GetMessagesAsync().FlattenAsync();

                                foreach (var messagefound in messages)
                                {
                                    await messagefound.DeleteAsync();

                                    await Task.Delay(1000);
                                }
                                if (messages.Count() == 0)
                                {
                                    loop = false;
                                }
                            }
                            catch { loop = false; }
                        }
                        foreach (var stringmes in GoogleData.ReadRules())
                        {
                            if (stringmes == "\n")
                            {
                                // None
                            }
                            else
                            {
                                await client.GetGuild(486327167035244554).GetTextChannel(channel.Id).SendMessageAsync(stringmes);
                            }
                            await Task.Delay(500);
                        }
                        break;
                    }
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "giant"))
            {
                DiscordFunctions.EmbedThisImage("Better watch out!", "", "https://pbs.twimg.com/media/EHnQ_CcWoAAMhqG?format=png&name=360x360", "red", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "everyone"))
            {
                // Make sure we have all parts
                if (Validation.WordCountEqual(message, 2))
                {
                    using (var db = new LiteDatabase(@"Config.db"))
                    {
                        var DatabaseConfig = db.GetCollection <DatabaseConfig>("DatabaseConfig");
                        var Config         = DatabaseConfig.FindOne(x => x.Id.Equals(1));
                        if (DatabaseConfig.Count() == 0)
                        {
                            Config.Everyonetag  = false;
                            Config.TweetChannel = "announcements";
                            DatabaseConfig.Insert(Config);
                        }
                        if (DiscordFunctions.GetWord(message, 1).ToLower() == "true")
                        {
                            Config.Everyonetag = true;
                            DatabaseConfig.Update(Config);
                            DiscordFunctions.EmbedThis("Value Updated", message.Author.Mention + " Value is now true", "green", context);
                        }
                        else if (DiscordFunctions.GetWord(message, 1).ToLower() == "false")
                        {
                            Config.Everyonetag = false;
                            DatabaseConfig.Update(Config);
                            DiscordFunctions.EmbedThis("Value Updated", message.Author.Mention + " Value is now false", "green", context);
                        }
                        else
                        {
                            DiscordFunctions.EmbedThis("Error", message.Author.Mention + " Value must be true or false", "red", context);
                        }
                    }
                }
                else
                {
                    DiscordFunctions.EmbedThis("Incomplete Command", "!everyone true", "", context);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "tweetchannel"))
            {
                // Make sure we have all parts
                if (Validation.WordCountEqual(message, 2))
                {
                    using (var db = new LiteDatabase(@"Config.db"))
                    {
                        var DatabaseConfig = db.GetCollection <DatabaseConfig>("DatabaseConfig");
                        var Config         = DatabaseConfig.FindOne(x => x.Id.Equals(1));
                        if (DatabaseConfig.Count() == 0)
                        {
                            Config.Everyonetag  = false;
                            Config.TweetChannel = "announcements";
                            DatabaseConfig.Insert(Config);
                        }
                        Config.TweetChannel = DiscordFunctions.GetWord(message, 1).ToLower().Replace("#", "");
                        DatabaseConfig.Update(Config);
                        DiscordFunctions.EmbedThis("Tweet Channel Update", "New tweet channel is" + DiscordFunctions.GetWord(message, 1), "green", context);
                    }
                }
                else
                {
                    DiscordFunctions.EmbedThis("Incomplete Command", "!tweetchannel #channel", "red", context);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "debuglist"))
            {
                using (var db = new LiteDatabase(@"Guardians.db"))
                {
                    var Guardians = db.GetCollection <UserData>("Guardians");
                    var results   = Guardians.FindAll();
                    Console.WriteLine("-----------------Guardians-------------------");
                    foreach (UserData user in results)
                    {
                        Console.WriteLine(user.Id + " " + user.DiscordUsername + " " + user.Team + " " + user.Event + " " + user.GroupMeGroup + " " + user.GroupMeTime);
                    }
                }
                using (var db = new LiteDatabase(@"Events.db"))
                {
                    var Events  = db.GetCollection <Events>("Events");
                    var results = Events.FindAll();
                    Console.WriteLine("-----------------Events-------------------");
                    foreach (Events user in results)
                    {
                        Console.WriteLine(user.Id + " " + user.Event);
                    }
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "reload"))
            {
                // Load the Database from google sheets
                List <UserData> users = GoogleData.ReadDB();
                using (var db = new LiteDatabase(@"Guardians.db"))
                {
                    var           Guardians = db.GetCollection <UserData>("Guardians");
                    List <string> ErrorList = new List <string>();
                    foreach (UserData user in users)
                    {
                        UserData Guardian = null;
                        foreach (var Guard in Guardians.FindAll())
                        {
                            if (Guard.DiscordUsername.ToLower().Trim().Contains(user.DiscordUsername.ToLower().Trim()))
                            {
                                Guardian = Guard;
                                break;
                            }
                        }
                        if (Guardian != null)
                        {
                            Guardian.Team = user.Team;
                            Guardians.Update(Guardian);
                        }
                        else
                        {
                            if (user.DiscordUsername.Contains("#"))
                            {
                                try
                                {
                                    using (var eventdb = new LiteDatabase(@"Events.db"))
                                    {
                                        var Events = eventdb.GetCollection <Events>("Events");
                                        var Event  = Events.FindAll();

                                        Guardian = new UserData
                                        {
                                            Event           = Event.First().Event,
                                            DiscordUsername = user.DiscordUsername,
                                            Team            = user.Team,
                                            Authenticated   = false
                                        };
                                        Guardians.Insert(Guardian);
                                    }
                                }
                                catch
                                {
                                    ErrorList.Add(user.DiscordUsername);
                                }
                            }
                            else
                            {
                                ErrorList.Add(user.DiscordUsername);
                            }
                        }
                    }
                    if (ErrorList.Count != 0)
                    {
                        string csv = String.Join(",\n", ErrorList.Select(x => x.ToString()).ToArray());
                        System.IO.File.WriteAllText("/opt/files/ErrorUsers.csv", csv);
                        await message.Channel.SendFileAsync("/opt/files/ErrorUsers.csv", "Users with Errors");

                        System.IO.File.Delete("/opt/files/ErrorUsers.csv");
                    }
                    // Index document using a document property
                    Guardians.EnsureIndex(x => x.DiscordUsername);
                }
                // Notify the user the DB reload has completed
                DiscordFunctions.EmbedThis("The DB has been reloaded", "", "green", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "withdraw"))
            {
                // Make sure we have all parts
                if (Validation.WordCountEqual(message, 2))
                {
                    if (DiscordFunctions.GetWord(message, 1).Contains("#"))
                    {
                        using (var db = new LiteDatabase(@"Guardians.db"))
                        {
                            var      Guardians = db.GetCollection <UserData>("Guardians");
                            UserData Guardian  = Guardians.FindOne(x => x.DiscordUsername.ToLower().StartsWith(DiscordFunctions.GetWord(message, 1).ToLower()));
                            if (Guardian != null)
                            {
                                bool found = false;
                                Console.WriteLine(Guardian.DiscordUsername);
                                foreach (var user in await context.Guild.GetUsersAsync())
                                {
                                    if (user.Username.ToLower() + "#" + user.Discriminator.ToString() == Guardian.DiscordUsername.ToLower())
                                    {
                                        if (user.RoleIds.Count == 2)
                                        {
                                            foreach (var role in user.Guild.Roles)
                                            {
                                                if (user.Guild.EveryoneRole != role && user.RoleIds.Contains(role.Id))
                                                {
                                                    await user.RemoveRoleAsync(role);
                                                }
                                            }
                                            foreach (var role in user.Guild.Roles)
                                            {
                                                if (role.Name.ToLower() == "global entry")
                                                {
                                                    await user.AddRoleAsync(role);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            List <string> eventroles = new List <string>();
                                            foreach (var role in user.Guild.Roles)
                                            {
                                                if (user.Guild.EveryoneRole != role && user.RoleIds.Contains(role.Id))
                                                {
                                                    if (role.Name.ToLower().Contains("guardian-austin-"))
                                                    {
                                                        eventroles.Add(role.Name);
                                                    }
                                                }
                                            }
                                            List <int> eventnumber = new List <int>();
                                            foreach (string role in eventroles)
                                            {
                                                eventnumber.Add(Int32.Parse(role.ToLower().Replace("guardian-austin-", "")));
                                            }
                                            foreach (var role in user.Guild.Roles)
                                            {
                                                if (user.Guild.EveryoneRole != role && user.RoleIds.Contains(role.Id))
                                                {
                                                    if (role.Name.ToLower() == "guardian-austin-" + eventnumber.Max().ToString())
                                                    {
                                                        await user.RemoveRoleAsync(role);
                                                    }
                                                }
                                            }
                                        }
                                        DiscordFunctions.EmbedThis("Users Removed", "Please remember to remove the user from the sheet", "orange", context);
                                        found = true;
                                        break;
                                    }
                                }
                                Guardians.Delete(Guardian.Id);
                                if (found == false)
                                {
                                    DiscordFunctions.EmbedThis("Unable to locate user in Discord", "User Removed from Database", "green", context);
                                }
                            }
                            else
                            {
                                DiscordFunctions.EmbedThis("Error", "User is not a guardian", "red", context);
                            }
                        }
                    }
                    else
                    {
                        DiscordFunctions.EmbedThis("Incomplete Command", "!withdraw user", "", context);
                    }
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "newevent"))
            {
                // Make sure we have all parts
                if (Validation.WordCountEqual(message, 3))
                {
                    using (var db = new LiteDatabase(@"Events.db"))
                    {
                        var Events = db.GetCollection <Events>("Events");

                        Events Eventexists = Events.FindOne(x => x.Event.ToLower().StartsWith(DiscordFunctions.GetWord(message, 1).ToLower() + "-" + DiscordFunctions.GetWord(message, 2).ToLower()));
                        if (Eventexists == null)
                        {
                            Events NewEvent = new Events
                            {
                                Event = DiscordFunctions.GetWord(message, 1) + "-" + DiscordFunctions.GetWord(message, 2)
                            };
                            Events.Insert(NewEvent);
                        }
                    }
                    // Send a message saying we sre starting
                    DiscordFunctions.EmbedThisImage("New Event Generating", "Please give it a few minutes (5+) to complete", "https://i.imgur.com/Gyn3f3T.gifv", "orange", context);

                    await NewEventBuilder.GenerateRolesAsync(context, DiscordFunctions.GetWord(message, 1), Convert.ToInt32(DiscordFunctions.GetWord(message, 2)));

                    await NewEventBuilder.GenerateCategoriesAsync(context, DiscordFunctions.GetWord(message, 1), Convert.ToInt32(DiscordFunctions.GetWord(message, 2)));

                    await NewEventBuilder.GenerateChannelsAsync(context, DiscordFunctions.GetWord(message, 1), Convert.ToInt32(DiscordFunctions.GetWord(message, 2)));

                    DiscordFunctions.EmbedThisImage("New Event Generating Complete", "", "", "green", context);
                }
                else
                {
                    // Warn the user it was a bad command
                    DiscordFunctions.EmbedThis("Incomplete Command", "!newevent EVENT YEAR", "", context);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "cleardb"))
            {
                using (var db = new LiteDatabase(@"Guardians.db"))
                {
                    var Guardians = db.GetCollection <UserData>("Guardians");
                    foreach (var Guardian in Guardians.FindAll())
                    {
                        if (Guardian.Authenticated == false)
                        {
                            Guardians.Delete(Guardian.Id);
                        }
                    }
                }
                DiscordFunctions.EmbedThis("Users Removed", "", "orange", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "unauthenticated"))
            {
                using (var db = new LiteDatabase(@"Guardians.db"))
                {
                    var           Guardians           = db.GetCollection <UserData>("Guardians");
                    List <string> UnauthenticatedList = new List <string>();
                    var           Guardianlist        = Guardians.FindAll();
                    foreach (var Guardian in Guardianlist)
                    {
                        if (Guardian.Authenticated == false)
                        {
                            UnauthenticatedList.Add(Guardian.DiscordUsername);
                        }
                    }
                    string csv = String.Join(",\n", UnauthenticatedList.Select(x => x.ToString()).ToArray());
                    System.IO.File.WriteAllText("/opt/files/unauth.csv", csv);
                    await message.Channel.SendFileAsync("/opt/files/unauth.csv", "Unauthenticated users");

                    System.IO.File.Delete("/opt/files/unauth.csv");
                }
                return(true);
            }
            return(false);
        }
Пример #7
0
        public static async System.Threading.Tasks.Task <bool> TeamCommand(SocketMessage message, CommandContext context)
        {
            if (Validation.CheckCommand(message, "squadlead"))
            {
                // Make sure we have all parts
                if (Validation.WordCountEqual(message, 2))
                {
                    if (DiscordFunctions.GetWord(message, 2).Contains("@"))
                    {
                        foreach (SocketRole rolesfound in ((SocketGuildUser)message.Author).Roles)
                        {
                            if (rolesfound.Name.ToLower().Contains("team-lead-"))
                            {
                                await DiscordFunctions.SquadLeadTask(context, rolesfound.Name, DiscordFunctions.GetWord(message, 2));

                                DiscordFunctions.EmbedThis("User is now a squad lead", message.Author.Username, "green", context);
                                break;
                            }
                        }
                    }
                    else
                    {
                        DiscordFunctions.EmbedThis("Incomplete Command", "!squadlead @user", "red", context);
                    }
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "squad"))
            {
                // Make sure we have all parts
                if (Validation.WordCountEqual(message, 2))
                {
                    if (DiscordFunctions.GetWord(message, 2).Contains("@"))
                    {
                        foreach (SocketRole rolesfound in ((SocketGuildUser)message.Author).Roles)
                        {
                            if (rolesfound.Name.ToLower().Contains("team-lead-"))
                            {
                                await DiscordFunctions.SquadTask(context, DiscordFunctions.GetWord(message, 3), DiscordFunctions.GetWord(message, 2), rolesfound.Name.Replace("team-lead-", ""));

                                DiscordFunctions.EmbedThis("User added to squad", message.Author.Username + " -> " + DiscordFunctions.GetWord(message, 3), "green", context);
                                break;
                            }
                        }
                    }
                    else
                    {
                        DiscordFunctions.EmbedThis("Incomplete Command", "!squad @user squadname", "red", context);
                    }
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "addchannel"))
            {
                // Make sure we have all parts
                if (Validation.WordCountGreater(message, 2))
                {
                    foreach (SocketRole rolesfound in ((SocketGuildUser)message.Author).Roles)
                    {
                        if (rolesfound.Name.ToLower().Contains("team-lead-"))
                        {
                            var teamname    = rolesfound.Name.ToLower().Trim().Replace("team-lead-", "");
                            var description = message.Content.Replace("!addchannel " + DiscordFunctions.GetWord(message, 1), "").Trim();
                            if (description.Length == 0)
                            {
                                description = " ";
                            }
                            await DiscordFunctions.CreateChannel(context, DiscordFunctions.GetWord(message, 1) + "-" + teamname, null, description, teamname, 2);

                            DiscordFunctions.EmbedThis("Channel Added", "", "green", context);
                        }
                    }
                }
                else
                {
                    DiscordFunctions.EmbedThis("Incomplete Command", "!addchannel channelname description", "red", context);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "deletechannel"))
            {
                // Make sure we have all parts
                if (Validation.WordCountEqual(message, 2))
                {
                    foreach (SocketRole rolesfound in ((SocketGuildUser)message.Author).Roles)
                    {
                        if (rolesfound.Name.ToLower().Contains("team-lead-"))
                        {
                            var  teamname = rolesfound.Name.ToLower().Trim().Replace("team-lead-", "");
                            bool found    = false;
                            foreach (var role in context.Guild.Roles)
                            {
                                if (role.Name.ToLower() == teamname)
                                {
                                    foreach (var channel in await context.Guild.GetChannelsAsync())
                                    {
                                        if (channel.Name == DiscordFunctions.GetWord(message, 1))
                                        {
                                            foreach (var perm in channel.PermissionOverwrites)
                                            {
                                                if (perm.TargetId == role.Id)
                                                {
                                                    await channel.DeleteAsync();

                                                    found = true;
                                                    break;
                                                }
                                            }
                                        }
                                        if (found == true)
                                        {
                                            break;
                                        }
                                    }
                                }
                                if (found == true)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    DiscordFunctions.EmbedThis("Incomplete Command", "!deletechannel channelname", "red", context);
                }
                return(true);
            }
            return(false);
        }
Пример #8
0
 public static async System.Threading.Tasks.Task <bool> PhoneCommands(SocketMessage message, DiscordSocketClient client)
 {
     if (Validation.CheckCommand(message, "sms"))
     {
         using (var db = new LiteDatabase(@"Guardians.db"))
         {
             string curDir = Directory.GetCurrentDirectory();
             // Assuming everything exists load in the json file
             string   credsfile = File.ReadAllText(curDir + "/botsettings.json");
             Config   creds     = JsonConvert.DeserializeObject <Config>(credsfile);
             var      Guardians = db.GetCollection <UserData>("Guardians");
             UserData Guardian  = Guardians.FindOne(x => x.DiscordUsername.ToLower().StartsWith(message.Author.Username.ToLower() + "#" + message.Author.Discriminator.ToString()));
             if (Guardian != null)
             {
                 if (Guardian.GroupMeGroup == null)
                 {
                     var result = GroupMe.CreateGroup(message.Author.Username + "#" + message.Author.Discriminator.ToString(), creds.GroupMe);
                     Guardian.GroupMeGroup = result.Item3;
                     Guardian.GroupMeTime  = DateTime.Now.ToString();
                     Guardian.Channels     = new List <string>()
                     {
                         "announcements", "announcements-" + Guardian.Event
                     };
                     Guardian.GroupMeBot = GroupMe.CreateBot(result.Item3, creds.GroupMe);
                     Guardians.Update(Guardian);
                     await message.Author.SendMessageAsync("Enable SMS: Link will only work once \nhttps://app.groupme.com/join_group/" + result.Item1 + "/" + result.Item2 + "\nPlease remember to enable SMS notifications in GroupMe via https://web.groupme.com/settings\nYou can also reply to SMS messages using this format `channelname:message`");
                 }
                 else
                 {
                     GroupMe.DeleteGroup(Guardian.GroupMeGroup, creds.GroupMe);
                     Guardian.GroupMeGroup = null;
                     Guardian.GroupMeTime  = null;
                     Guardian.Channels     = null;
                     Guardian.GroupMeBot   = null;
                     Guardians.Update(Guardian);
                     await message.Author.SendMessageAsync("SMS Link has been deleted");
                 }
             }
             else
             {
                 await message.Channel.SendMessageAsync("User is not a Guardian, unable to set up SMS notifications");
             }
         }
         return(true);
     }
     else if (Validation.CheckCommand(message, "notify"))
     {
         using (var db = new LiteDatabase(@"Guardians.db"))
         {
             var      Guardians = db.GetCollection <UserData>("Guardians");
             UserData Guardian  = Guardians.FindOne(x => x.DiscordUsername.ToLower().StartsWith(message.Author.Username.ToLower() + "#" + message.Author.Discriminator.ToString()));
             if (Guardian != null)
             {
                 if (Guardian.GroupMeGroup != null)
                 {
                     string chan = "";
                     try
                     {
                         string temp = DiscordFunctions.GetWord(message, 1).ToLower();
                         foreach (var channel in client.GetGuild(405513567681642517).Channels)
                         {
                             bool found = false;
                             foreach (var person in channel.Users)
                             {
                                 if (person.Id == message.Author.Id)
                                 {
                                     found = true;
                                 }
                             }
                             if (temp == channel.Name.ToLower() && found == true)
                             {
                                 chan = channel.Name.ToLower();
                                 break;
                             }
                         }
                     }
                     catch
                     {
                         chan = message.Channel.Name.ToLower();
                     }
                     if (chan != "")
                     {
                         if (Guardian.Channels == null)
                         {
                             Guardian.Channels = new List <string>()
                             {
                                 chan
                             };
                             await message.Author.SendMessageAsync("Channel: " + chan + " was added to your notifications");
                         }
                         else
                         {
                             if (Guardian.Channels.Contains(chan))
                             {
                                 List <string> channels = Guardian.Channels;
                                 channels.Remove(chan);
                                 await message.Author.SendMessageAsync("Channel: " + chan + " was removed");
                             }
                             else
                             {
                                 List <string> channels = Guardian.Channels;
                                 channels.Add(chan);
                                 Guardian.Channels = channels;
                                 await message.Author.SendMessageAsync("Channel: " + chan + " was added to your notifications");
                             }
                         }
                         Guardians.Update(Guardian);
                     }
                     else
                     {
                         await message.Author.SendMessageAsync("Channel either does not exist or you do not have permissions to view it");
                     }
                 }
             }
         }
         return(true);
     }
     return(false);
 }