Ejemplo n.º 1
0
        public async Task RolemeAsync([Remainder] string inRoleStr = "display")
        {
            if (Context.IsPrivate)
            {
                await ReplyAsync("**This command can not be used in a DM**");

                return;
            }

            var user = Context.User as SocketGuildUser;

            //Display roles, or modify role state
            if (inRoleStr.ToLower() == "display")
            {
                await ReplyAsync($"Valid roles are:```\n{string.Join("\n", _dataServices.roleMeWhiteList)}```");
            }
            else
            {
                //Validate that we can apply the role
                Boolean valid = false;
                string  reply = null;
                foreach (string s in _dataServices.roleMeWhiteList)
                {
                    if (inRoleStr.ToLower().Contains(s.ToLower()))
                    {
                        valid = true; //We applied at least 1 role.

                        var inRole = Context.Guild.Roles.FirstOrDefault(x => x.Name == s);

                        if (user.Roles.Contains(inRole))
                        {
                            reply += $"{Context.User.Username} lost the **{inRole}** role.\n";
                            await(user as IGuildUser).RemoveRoleAsync(inRole);
                        }
                        else
                        {
                            reply += $"{Context.User.Username} now has the role **{inRole}**. Enjoy the flair!\n";
                            await(user as IGuildUser).AddRoleAsync(inRole);
                        }
                    }
                }

                if (valid)
                {
                    await ReplyAsync($"{reply}");

                    await _dataServices.ChannelLog($"{Context.User}\n{reply}");
                }
                else
                {
                    await ReplyAsync($"{Context.User.Mention}\n```You cannot assign yourself the role of **{inRoleStr}** because it does not exist, " +
                                     $"or it is not allowed.```");

                    await _dataServices.ChannelLog($"{Context.User} attempted to roleMe the role of: {inRoleStr} and it failed. Either due to the " +
                                                   $"role not existing, or they tried to use a role that isn't in the white list.");
                }
            }
        }
Ejemplo n.º 2
0
 public void Cycle()
 {
     //Check for unmutes
     foreach (UserData u in muteList.ToList())
     {
         if (!(u.User).Roles.Contains(_dataServices.MuteRole))
         {
             _dataServices.ChannelLog($"{u.User} was manually unmuted from someone removing the role.", "Removing them from the mute list.");
             muteList.Remove(u);
         }
         if (u.CanUnmute())
         {
             u.User.RemoveRoleAsync(_dataServices.MuteRole);
             u.User.SendMessageAsync("You have been unmuted!");
             muteList.Remove(u);
             _dataServices.ChannelLog($"{u.User} Has been unmuted.");
             Task.Delay(1000);
         }
     }
 }
Ejemplo n.º 3
0
        public async Task Test_NextMessageAsync()
        {
            if (Context.IsPrivate)
            {
                await ReplyAsync("```This command can not be used in a DM```");

                return;
            }
            if ((Context.User as SocketGuildUser).Roles.Contains(_dataServices.ModRole))
            {
                await Context.Message.DeleteAsync();

                var embedLayout = new EmbedBuilder()
                {
                    ImageUrl = "https://content.tophattwaffle.com/BotHATTwaffle/embed.png",
                };

                string embedDescription = null;
                Color  embedColor       = new Color(243, 128, 72);
                string embedThumbUrl    = null;
                string embedTitle       = null;
                string embedURL         = null;
                string footText         = null;
                string authName         = null;
                string footIconURL      = null;
                string embedImageURL    = null;

                List <EmbedFieldBuilder> fieldBuilder = new List <EmbedFieldBuilder>();
                var authBuilder = new EmbedAuthorBuilder()
                {
                    Name    = authName,
                    IconUrl = Context.Message.Author.GetAvatarUrl(),
                };
                var footBuilder = new EmbedFooterBuilder()
                {
                    Text    = footText,
                    IconUrl = footIconURL
                };
                var builder = new EmbedBuilder()
                {
                    Fields = fieldBuilder,
                    Footer = footBuilder,
                    Author = authBuilder,

                    ImageUrl     = embedImageURL,
                    Url          = embedURL,
                    Title        = embedTitle,
                    ThumbnailUrl = embedThumbUrl,
                    Color        = embedColor,
                    Description  = embedDescription
                };
                Boolean submit          = false;
                string  instructionsStr = "Type one of the options. Do not include `>`. Auto timeout in 120 seconds:" +
                                          "\n`Author Name` `Thumbnail` `Title` `URL` `Color` `Description` `Image` `Field` `Footer Text`" +
                                          "\n`submit` to send it." +
                                          "\n`cancel` to abort.";
                var pic = await ReplyAsync("", false, embedLayout);

                var preview = await ReplyAsync("__**PREVIEW**__", false, builder);

                var instructions = await ReplyAsync(instructionsStr);

                Boolean run = true;
                while (run)
                {
                    var response = await NextMessageAsync();

                    if (response != null)
                    {
                        try
                        {
                            await response.DeleteAsync();
                        }
                        catch { }
                        Boolean valid = true;
                        switch (response.Content.ToLower())
                        {
                        case "author name":
                            await instructions.ModifyAsync(x =>
                            {
                                x.Content = "Enter Author Name text:";
                            });

                            response = await NextMessageAsync();

                            if (response != null)
                            {
                                authName = response.Content;
                            }
                            break;

                        case "thumbnail":
                            await instructions.ModifyAsync(x =>
                            {
                                x.Content = "Enter Thumbnail URL:";
                            });

                            response = await NextMessageAsync();

                            if (response != null)
                            {
                                if (Uri.IsWellFormedUriString(response.Content, UriKind.Absolute))
                                {
                                    embedThumbUrl = response.Content;
                                }
                                else
                                {
                                    await ReplyAndDeleteAsync("```INVALID URL!```", timeout : TimeSpan.FromSeconds(3));
                                }
                            }
                            break;

                        case "title":
                            await instructions.ModifyAsync(x =>
                            {
                                x.Content = "Enter Title text:";
                            });

                            response = await NextMessageAsync();

                            if (response != null)
                            {
                                embedTitle = response.Content;
                            }
                            break;

                        case "url":
                            await instructions.ModifyAsync(x =>
                            {
                                x.Content = "Enter Title URL:";
                            });

                            response = await NextMessageAsync();

                            if (response != null)
                            {
                                if (Uri.IsWellFormedUriString(response.Content, UriKind.Absolute))
                                {
                                    embedURL = response.Content;
                                }
                                else
                                {
                                    await ReplyAndDeleteAsync("```INVALID URL!```", timeout : TimeSpan.FromSeconds(3));
                                }
                            }
                            break;

                        case "color":
                            await instructions.ModifyAsync(x =>
                            {
                                x.Content = "Enter Color in form of `R G B` Example: `250 120 50` :";
                            });

                            response = await NextMessageAsync();

                            if (response != null)
                            {
                                string[] splitString = { null, null, null };
                                splitString = response.Content.Split(' ');
                                try
                                {
                                    var splitInts = splitString.Select(item => int.Parse(item)).ToArray();
                                    embedColor = new Color(splitInts[0], splitInts[1], splitInts[2]);
                                }
                                catch
                                {
                                    await ReplyAndDeleteAsync("```INVALID R G B STRUCTURE!```", timeout : TimeSpan.FromSeconds(3));
                                }
                            }
                            break;

                        case "description":
                            await instructions.ModifyAsync(x =>
                            {
                                x.Content = "Enter Description text:";
                            });

                            response = await NextMessageAsync();

                            if (response != null)
                            {
                                embedDescription = response.Content;
                            }
                            break;

                        case "image":
                            await instructions.ModifyAsync(x =>
                            {
                                x.Content = "Enter Image URL:";
                            });

                            response = await NextMessageAsync();

                            if (response != null)
                            {
                                if (Uri.IsWellFormedUriString(response.Content, UriKind.Absolute))
                                {
                                    embedImageURL = response.Content;
                                }
                                else
                                {
                                    await ReplyAndDeleteAsync("```INVALID URL!```", timeout : TimeSpan.FromSeconds(3));
                                }
                            }
                            break;

                        case "field":
                            await instructions.ModifyAsync(x =>
                            {
                                x.Content = "Enter Field Name text:";
                            });

                            response = await NextMessageAsync();

                            if (response != null)
                            {
                                string fTitle = response.Content;
                                await response.DeleteAsync();

                                await instructions.ModifyAsync(x =>
                                {
                                    x.Content = "Enter Field Content text:";
                                });

                                response = await NextMessageAsync();

                                if (response != null)
                                {
                                    string fContent = response.Content;
                                    await response.DeleteAsync();

                                    await instructions.ModifyAsync(x =>
                                    {
                                        x.Content = "Inline? [T]rue or [F]alse?";
                                    });

                                    Boolean fInline = false;

                                    response = await NextMessageAsync();

                                    if (response != null)
                                    {
                                        if (response.Content.ToLower() == "t" || response.Content.ToLower() == "true")
                                        {
                                            fInline = true;
                                        }

                                        fieldBuilder.Add(new EmbedFieldBuilder {
                                            Name = fTitle, Value = fContent, IsInline = fInline
                                        });
                                    }
                                }
                            }
                            break;

                        case "footer text":
                            await instructions.ModifyAsync(x =>
                            {
                                x.Content = "Enter Footer text:";
                            });

                            response = await NextMessageAsync();

                            if (response != null)
                            {
                                footText = response.Content;
                            }
                            break;

                        case "submit":
                            submit = true;
                            await preview.DeleteAsync();

                            await instructions.DeleteAsync();

                            await pic.DeleteAsync();

                            run   = false;
                            valid = false;
                            break;

                        case "cancel":
                            await preview.DeleteAsync();

                            await instructions.DeleteAsync();

                            await pic.DeleteAsync();

                            run   = false;
                            valid = false;
                            break;

                        default:
                            await ReplyAndDeleteAsync("```UNKNOWN OPTION. PLEASE ENTER ONLY THE OPTIONS LISTED ABOVE.\nFor example \"title\"```", timeout : TimeSpan.FromSeconds(5));

                            valid = false;
                            break;
                        }
                        if (valid) //Unknown command was sent. Don't delete.
                        {
                            try
                            {
                                await response.DeleteAsync();
                            }
                            catch { }
                        }

                        authBuilder = new EmbedAuthorBuilder()
                        {
                            Name    = authName,
                            IconUrl = Context.Message.Author.GetAvatarUrl()
                        };
                        footBuilder = new EmbedFooterBuilder()
                        {
                            Text    = footText,
                            IconUrl = Context.Message.Author.GetAvatarUrl()
                        };
                        builder = new EmbedBuilder()
                        {
                            Fields = fieldBuilder,
                            Footer = footBuilder,
                            Author = authBuilder,

                            ImageUrl     = embedImageURL,
                            Url          = embedURL,
                            Title        = embedTitle,
                            ThumbnailUrl = embedThumbUrl,
                            Color        = embedColor,
                            Description  = embedDescription
                        };
                        if (valid)
                        {
                            await preview.ModifyAsync(x =>
                            {
                                x.Content = "__**PREVIEW**__";
                                x.Embed   = builder.Build();
                            });

                            await instructions.ModifyAsync(x =>
                            {
                                x.Content = instructionsStr;
                            });
                        }
                    }
                    else
                    {
                        await ReplyAsync("```Announce Builder Timed out after 120 seconds!!```");

                        await instructions.DeleteAsync();

                        await pic.DeleteAsync();

                        await preview.DeleteAsync();
                    }
                }

                if (submit)
                {
                    var msg = await ReplyAsync("Send this to what channel?", false, builder);

                    Boolean sent = false;
                    while (!sent)
                    {
                        var response = await NextMessageAsync();

                        if (response != null)
                        {
                            if (response.Content.ToLower() == "cancel")
                            {
                                return;
                            }

                            foreach (SocketTextChannel s in Context.Guild.TextChannels)
                            {
                                if (s.Name.ToLower() == response.Content)
                                {
                                    await s.SendMessageAsync("", false, builder);

                                    await _dataServices.ChannelLog($"Embed created by {Context.User} was sent to {s.Name}!");

                                    await _dataServices.logChannel.SendMessageAsync("", false, builder);

                                    sent = true;
                                    await msg.ModifyAsync(x =>
                                    {
                                        x.Content = "__**SENT!**__";
                                        x.Embed   = builder.Build();
                                    });

                                    await response.DeleteAsync();

                                    return;
                                }
                            }
                            await ReplyAndDeleteAsync("```CHANNEL NOT FOUND TRY AGAIN.```", timeout : TimeSpan.FromSeconds(3));

                            await response.DeleteAsync();
                        }
                        else
                        {
                            await msg.DeleteAsync();
                            await ReplyAsync("```Announce Builder Timed out after 120 seconds!!```");
                        }
                    }
                }
            }
            else
            {
                await _dataServices.ChannelLog($"{Context.User} is trying to announce from the bot.");
                await ReplyAsync("```You cannot use this command with your current permission level!```");
            }
        }
Ejemplo n.º 4
0
        public async Task PublicTestStartAsync(string serverStr = null, string mapID = null)
        {
            if (Context.IsPrivate)
            {
                await ReplyAsync("***This command can not be used in a DM***");

                return;
            }

            if ((Context.User as SocketGuildUser).Roles.Contains(_dataServices.ActiveRole))
            {
                if (!_levelTesting.canReserve)
                {
                    await ReplyAsync($"```Servers cannot be reserved at this time." +
                                     $"\nServer reservation is blocked 1 hour before a scheduled test, and resumes once the calendar event has passed.```");

                    return;
                }

                foreach (UserData u in _levelTesting.userData)
                {
                    if (u.User == Context.Message.Author)
                    {
                        TimeSpan timeLeft = u.ServerReleaseTime.Subtract(DateTime.Now);
                        await ReplyAsync($"```You have a reservation on {u.Server.Name}. You have {timeLeft.ToString("h'H 'm'M'")} left.```");

                        return;
                    }
                }

                //Display list of servers
                if (serverStr == null && mapID == null)
                {
                    await ReplyAsync("", false, _dataServices.GetAllServers());

                    return;
                }

                var server = _dataServices.GetServer(serverStr);

                if (server == null)
                {
                    var authBuilder = new EmbedAuthorBuilder()
                    {
                        Name    = $"Hey there {Context.Message.Author.Username}!",
                        IconUrl = Context.Message.Author.GetAvatarUrl(),
                    };

                    var builder = new EmbedBuilder()
                    {
                        Author       = authBuilder,
                        ThumbnailUrl = "https://www.tophattwaffle.com/wp-content/uploads/2017/11/1024_png-300x300.png",
                        Color        = new Color(243, 128, 72),

                        Description = $"I could not find a server with that prefix." +
                                      $"\nA server can be reserved by using `>PublicServer [serverPrefix]`. Using just `>PublicServer` will display all the servers you can use."
                    };
                    await ReplyAsync("", false, builder);

                    return;
                }

                //Check if there is already a reservation on that server
                if (_levelTesting.IsServerOpen(server))
                {
                    await _levelTesting.AddServerReservation((SocketGuildUser)Context.User, DateTime.Now.AddHours(2), server);

                    var authBuilder = new EmbedAuthorBuilder()
                    {
                        Name    = $"Hey there {Context.Message.Author} you have {server.Address} for 2 hours!",
                        IconUrl = Context.Message.Author.GetAvatarUrl(),
                    };
                    var footBuilder = new EmbedFooterBuilder()
                    {
                        Text    = $"This is in beta, please let TopHATTwaffle know if you have issues.",
                        IconUrl = Program._client.CurrentUser.GetAvatarUrl()
                    };
                    List <EmbedFieldBuilder> fieldBuilder = new List <EmbedFieldBuilder>();
                    fieldBuilder.Add(new EmbedFieldBuilder {
                        Name = "Connect Info", Value = $"`connect {server.Address}`", IsInline = false
                    });
                    fieldBuilder.Add(new EmbedFieldBuilder {
                        Name = "Links", Value = $"[Schedule a Playtest](https://www.tophattwaffle.com/playtesting/) | [View Testing Calendar](http://playtesting.tophattwaffle.com)", IsInline = false
                    });
                    var builder = new EmbedBuilder()
                    {
                        Fields       = fieldBuilder,
                        Footer       = footBuilder,
                        Author       = authBuilder,
                        ThumbnailUrl = "https://www.tophattwaffle.com/wp-content/uploads/2017/11/1024_png-300x300.png",
                        Color        = new Color(243, 128, 72),

                        Description = $"For the next 2 hours you can use:" +
                                      $"\n`>PublicCommand [command]` or `>pc [command]`" +
                                      $"\nTo send commands to the server. Example: `>pc mp_restartgame 1`" +
                                      $"\nTo see a list of the commands you can use, type `>pc`" +
                                      $"\nOnce the 2 hours has ended you won't have control of the server any more." +
                                      $"\n\n*If you cannot connect to the reserved server for any reason, please let TopHATTwaffle know!*"
                    };
                    await ReplyAsync("", false, builder);

                    if (mapID != null)
                    {
                        await Task.Delay(3000);

                        await _dataServices.RconCommand($"host_workshop_map {mapID}", server);
                    }
                }
                else
                {
                    DateTime time = DateTime.Now;
                    foreach (UserData u in _levelTesting.userData)
                    {
                        if (u.Server == server)
                        {
                            time = u.ServerReleaseTime;
                        }
                    }
                    TimeSpan timeLeft = time.Subtract(DateTime.Now);

                    var authBuilder = new EmbedAuthorBuilder()
                    {
                        Name    = $"Unable to Reserver Server for {Context.Message.Author.Username}!",
                        IconUrl = Context.Message.Author.GetAvatarUrl(),
                    };

                    var builder = new EmbedBuilder()
                    {
                        Author       = authBuilder,
                        ThumbnailUrl = "https://www.tophattwaffle.com/wp-content/uploads/2017/11/1024_png-300x300.png",
                        Color        = new Color(243, 128, 72),

                        Description = $"You cannot reserve the server {server.Name} because someone else is using it. Their reservation ends in {timeLeft.ToString("h'H 'm'M'")}" +
                                      $"\nYou can use `>sr` to see all current server reservations."
                    };
                    await ReplyAsync("", false, builder);
                }
            }
            else
            {
                await _dataServices.ChannelLog($"{Context.User} is trying to use public playtest commands without permission.");
                await ReplyAsync($"```You cannot use this command with your current permission level! You need {_dataServices.ActiveRole.Name} role.```");
            }
        }
Ejemplo n.º 5
0
        //Gets imgur album to random featured image
        private async Task GetAlbum()
        {
            canRandomImage = true;
            try
            {
                string albumURL = currentEventInfo[5];
                string albumID  = albumURL.Substring(albumURL.IndexOf("/a/") + 3);
                var    client   = new ImgurClient(_dataServices.imgurAPI);
                var    endpoint = new AlbumEndpoint(client);

                featureAlbum = await endpoint.GetAlbumAsync(albumID);

                string foundImages = null;

                foreach (var i in featureAlbum.Images)
                {
                    foundImages += $"{i.Link}\n";
                }

                await _dataServices.ChannelLog("Getting Imgur Info from IMGUR API", $"Album URL: {albumURL}" +
                                               $"\nAlbum ID: {albumID}" +
                                               $"\nClient Credits Remaining: {client.RateLimit.ClientRemaining} of {client.RateLimit.ClientLimit}" +
                                               $"\nImages Found: {foundImages}");
            }
            catch
            {
                await _dataServices.ChannelLog($"Unable to get Imgur Album for Random Image for {currentEventInfo[2]}", "Falling back to the image in the cal event.");

                canRandomImage = false;
            }
        }
Ejemplo n.º 6
0
        public async Task SearchAsync(string series, [Remainder] string search)
        {
            var wait = await ReplyAsync($":eyes: Searching for **{search}** in **{series}**. This may take a moment! :eyes:");

            await _dataServices.ChannelLog($"{Context.User} ran a search", $"Series: {series}\nSearch Term: {search}");

            //Is the message a DM?
            bool isPrivate = Context.IsPrivate;

            //Preform the search
            List <List <string> > results = _dataServices.Search(series, search, isPrivate);

            //A dump was requested
            if (search.ToLower() == "dump" || search.ToLower() == "all")
            {
                //[0]title
                //[1]url
                //[2]tags
                List <string> reply = new List <string>();
                string        text  = null;
                foreach (var r in results)
                {
                    text += $"[{r[0]}]({r[1]})\nTags: {r[2]}\n\n";

                    if (text.Length > 1800)
                    {
                        reply.Add(text);
                        text = null;
                    }
                }

                if (!string.IsNullOrEmpty(text))
                {
                    reply.Add(text);
                }

                try                 //If we cannot send a DM to the user, let them know.
                {
                    foreach (var s in reply)
                    {
                        var builder = new EmbedBuilder()
                        {
                            Color = new Color(243, 128, 72),

                            Description = s
                        };
                        await Context.User.SendMessageAsync("", false, builder);
                    }
                }
                catch
                {
                    await ReplyAsync("```\"dump\" and \"all\" search terms can ONLY send replies in a DM. This is to prevent flooding chat." +
                                     " You got this message because you do not accept DMs from non-friends.```");
                }

                if (!isPrivate)
                {
                    await wait.DeleteAsync();

                    //Delete the invoking message
                    await Context.Message.DeleteAsync();
                }

                return;
            }

            //There are no search results. Build a reply letting them know.
            if (results.Count == 0)
            {
                List <string> singleResult = new List <string>
                {
                    "Try a different search term",
                    "http://tophattwaffle.com/faq",
                    "I could not locate anything for the search term you provided. Please try a different search term.",
                    null
                };
                results.Add(singleResult);
            }

            foreach (var r in results)
            {
                var authBuilder = new EmbedAuthorBuilder()
                {
                    Name    = r[0],
                    IconUrl = "https://cdn.discordapp.com/icons/111951182947258368/0e82dec99052c22abfbe989ece074cf5.png"
                };

                var builder = new EmbedBuilder()
                {
                    Author = authBuilder,

                    Title        = $"Click Here",
                    Url          = r[1],
                    ThumbnailUrl = r[3],
                    Color        = new Color(243, 128, 72),

                    Description = r[2]
                };
                await ReplyAsync("", false, builder);
            }
            if (!isPrivate)
            {
                await wait.DeleteAsync();
            }
        }