private async Task ReactionAdded(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            var user = reaction.User.Value.ToString();

            SupportingMethods.updateDocument(user, "reactionCount", 1);

            UserInfo userInfo = SupportingMethods.getUserInformation(user);

            if (userInfo != null)
            {
                if (userInfo.ReactionCount >= 250)
                {
                    await addRole(reaction.User.Value as SocketGuildUser, "Overreaction", channel.Id);
                }
                else if (userInfo.ReactionCount >= 100)
                {
                    await addRole(reaction.User.Value as SocketGuildUser, "Major reaction", channel.Id);
                }
                else if (userInfo.ReactionCount >= 50)
                {
                    await addRole(reaction.User.Value as SocketGuildUser, "Reactionary", channel.Id);
                }
                else if (userInfo.ReactionCount >= 25)
                {
                    await addRole(reaction.User.Value as SocketGuildUser, "Reactor", channel.Id);
                }
            }
            else
            {
                await createUserInDatabase(reaction.User.Value as SocketUser, channel.Id);
            }
        }
        public async Task checkMessageCountForRole(SocketUser user, ulong channelID)
        {
            string   userName = user.ToString();
            UserInfo userInfo = SupportingMethods.getUserInformation(userName);

            if (userInfo != null)
            {
                if (userInfo.IsBetaTester)
                {
                    await addRole(user as SocketGuildUser, "Beta Tester", channelID);
                }
                if (userInfo.NumberOfMessages >= 10000)
                {
                    await addRole(user as SocketGuildUser, "I wrote a novel", channelID);
                }
                else if (userInfo.NumberOfMessages >= 1000)
                {
                    await addRole(user as SocketGuildUser, "I could write a novel", channelID);
                }
                else if (userInfo.NumberOfMessages >= 100)
                {
                    await addRole(user as SocketGuildUser, "I'm liking this server", channelID);
                }
                else if (userInfo.NumberOfMessages >= 1)
                {
                    await addRole(user as SocketGuildUser, "Hi and Welcome!", channelID);
                }
            }
            else
            {
                await createUserInDatabase(user, channelID);
            }
        }
        public async Task getRoleDesc([Summary("The role to get the description for")] string roleName)
        {
            var selectedRole = Context.Guild.Roles.FirstOrDefault(x => SupportingMethods.stringEquals(x.Name, roleName));
            var allRoles     = SupportingMethods.LoadAllRolesFromServer();
            var role         = allRoles.Find(x => SupportingMethods.stringEquals(x.Name, selectedRole.Name));

            await ReplyAsync($"To get ***{role.Name}***\n\t-{role.Description}\n\t-Difficulty: {role.Difficulty}");
        }
        public async Task addRole(SocketGuildUser user, string roleName, ulong channelID)
        {
            var userName     = user as SocketUser;
            var currentGuild = user.Guild as SocketGuild;
            var role         = currentGuild.Roles.FirstOrDefault(x => SupportingMethods.stringEquals(x.Name, roleName));

            if (!user.Roles.Contains(role))
            {
                await Logger.Log(new LogMessage(LogSeverity.Info, $"{GetType().Name}.addRole", $"{userName} has earned {roleName}"));

                await(user as IGuildUser).AddRoleAsync(role);
                var channelName = client.GetChannel(channelID) as IMessageChannel;
                await channelName.SendMessageAsync($"{userName} has earned **{role.Name}**");
            }
        }
        public async Task getExpLeaderboard([Summary("Places to see on leaderboard")] int userCount = 10)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("```css\n");
            string titleString = "Username".PadRight(30) + "| Total Experience";

            stringBuilder.Append(titleString);
            stringBuilder.Append("\n".PadRight(titleString.Length, '-') + "\n");
            try {
                var allUsers = new Dictionary <SocketGuildUser, int>();

                foreach (var user in (await Context.Guild.GetUsersAsync()))
                {
                    if (!user.IsBot)
                    {
                        var      userName = user as SocketUser;
                        UserInfo userInfo = SupportingMethods.getUserInformation(userName.ToString());
                        if (userInfo != null)
                        {
                            allUsers.Add(user as SocketGuildUser, userInfo.Experience);
                        }
                    }
                }
                if (allUsers.Count > 0)
                {
                    var sortedDict = from entry in allUsers orderby entry.Value descending select entry;
                    int i          = 0;
                    foreach (var entry in sortedDict)
                    {
                        stringBuilder.Append(entry.Key.ToString().PadRight(30) + "|\t" + entry.Value + "\n");
                        ++i;
                        if (i >= userCount)
                        {
                            break;
                        }
                    }
                    stringBuilder.Append("```");
                    await ReplyAsync($"{stringBuilder.ToString()}");
                }
                else
                {
                    await ReplyAsync($"{GetType().Name}.getExpLeaderboard Unexpected Exception");
                }
            } catch (Exception ex) {
                await Logger.Log(new LogMessage(LogSeverity.Error, $"{GetType().Name}.getExpLeaderboard", "Unexpected Exception", ex));
            }
        }
        public async Task HandleCommandAsync(SocketMessage messageParam)
        {
            string userName    = "";
            string channelName = "";
            string guildName   = "";
            int    argPos      = 0;

            try {
                var msg = messageParam as SocketUserMessage;

                userName    = GetUserName(msg.Author);
                channelName = msg.Channel?.Name ?? "NULL";
                var context = new CommandContext(client, msg);
                guildName = context.Guild?.Name ?? "NULL";
                var channelID = msg.Channel.Id;
                await Logger.Log(new LogMessage(LogSeverity.Info, $"{GetType().Name}.HandleCommandAsync", $"HandleCommandAsync G: {guildName} C: {channelName} User: {userName}  Msg: {msg}"));

                if (!msg.Author.IsBot)
                {
                    SupportingMethods.updateDocument(userName, "numberOfMessages", 1);
                    SupportingMethods.updateDocument(userName, "experience", msg.Content.Length);
                    await checkMessageCountForRole(msg.Author, channelID);
                }

                if (msg == null)
                {
                    return;
                }
                else if (msg.HasCharPrefix(CommandPrefix, ref argPos))
                {
                    var result = await commands.ExecuteAsync(context, argPos);

                    if (!result.IsSuccess)                     // If execution failed, reply with the error message.
                    {
                        string message = "Command Failed: " + msg;
                        await Logger.Log(new LogMessage(LogSeverity.Error, $"{GetType().Name}.HandleCommandAsync", message));

                        await context.Channel.SendMessageAsync(message);
                    }
                }
            } catch (Exception e) {
                await Logger.Log(new LogMessage(LogSeverity.Error, $"{GetType().Name}.HandleCommandAsync", $"G:{guildName} C:{channelName} U:{userName} Unexpected Exception {e}", e));
            }
        }
 public async Task getExperience([Summary("The user to get exp total from")] SocketGuildUser userName = null)
 {
     try {
         if (userName == null)
         {
             userName = ((SocketGuildUser)Context.Message.Author);
         }
         var      user     = userName as SocketUser;
         UserInfo userInfo = SupportingMethods.getUserInformation(user.ToString());
         if (userInfo != null)
         {
             var currentExp = userInfo.Experience;
             var level      = Math.Round(Math.Pow(currentExp, 1 / 1.3) / 100);
             await ReplyAsync($"{user} has {currentExp} experience and is level {level}");
         }
     } catch (Exception ex) {
         await Logger.Log(new LogMessage(LogSeverity.Error, GetType().Name + ".getExperience", "Unexpected Exception", ex));
     }
 }
        public async Task reorderRoles()
        {
            var allRoles      = SupportingMethods.LoadAllRolesFromServer().OrderBy(x => x.Difficulty).ToList();
            var allGuildRoles = Context.Guild.Roles.ToList();

            foreach (var irole in allGuildRoles)
            {
                foreach (var role in allRoles)
                {
                    if (role.Name == irole.Name)
                    {
                        await irole.ModifyAsync(x => x.Position = allRoles.IndexOf(role) + 1);

                        break;
                    }
                }
            }

            await ReplyAsync($"Roles have been reordered");
        }
        public async Task createRoles()
        {
            List <string> currentGuildRoles = new List <string>();

            foreach (SocketRole guildRoles in ((SocketGuild)Context.Guild).Roles)
            {
                currentGuildRoles.Add(guildRoles.Name);
            }

            foreach (var role in SupportingMethods.LoadAllRolesFromServer())
            {
                if (!currentGuildRoles.Contains(role.Name))
                {
                    var randColor = new Color(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256));
                    await Context.Guild.CreateRoleAsync(role.Name, GuildPermissions.None, randColor);

                    await Logger.Log(new LogMessage(LogSeverity.Verbose, GetType().Name + ".createRoles", "Added role to server: " + role.Name));
                    await ReplyAsync($"Added role: {role.Name}\nHow to get: {role.Description}");
                }
            }
        }
Exemplo n.º 10
0
        public async Task MainAsync()
        {
            Console.WriteLine("Which bot to run: ");
            string key = Console.ReadLine();

            if (key.Equals("debug"))
            {
                CommandPrefix = '?';
            }
            string token = GetKey.getKey(key);

            SupportingMethods.SetupMongoDatabase();
            SupportingMethods.SetupMongoCollection("userData");

            await commands.AddModulesAsync(Assembly.GetEntryAssembly());

            await client.LoginAsync(TokenType.Bot, token);

            await client.StartAsync();

            // Block this task until the program is closed.
            await Task.Delay(-1);
        }
Exemplo n.º 11
0
 private async Task createUserInDatabase(SocketUser userName, ulong id)
 {
     SupportingMethods.createUserInDatabase(userName);
     await addRole(userName as SocketGuildUser, "Family", id);
 }