Пример #1
0
        ServerCountAsync()
        {
            //Create and set the guild iterator.
            var guild = Program.g_client.Guilds.GetEnumerator();

            string description = $"The bot is on {Program.g_client.Guilds.Count} server(s)\n\n";
            //Create and set embed object.
            var embed = CoreModule.SimpleEmbed(Color.Blue,
                                               "Server count",
                                               null);

            //Loop guild iterator.
            while (guild.MoveNext())
            {
                //On
                try {
                    //Add to description.
                    description += $"Owner: **`{guild.Current.Owner.Username}#" +
                                   $"{guild.Current.Owner.Discriminator}`**," +
                                   $" Name: **`{guild.Current.Name}`**\n";
                }
                catch (NullReferenceException e) {
                    //Add to description.
                    description += $"**`{e.Message}`**, Name: **`{guild.Current.Name}`**\n";
                }
            }

            //Add description.
            embed.WithDescription(description);

            //Reply embed.
            await ReplyAsync("", false, embed.Build());
        }
Пример #2
0
        SetNotificationChannelAsync(SocketTextChannel _channel)
        {
            //On server has text channel.
            if (Context.Guild.Channels.Contains(_channel))
            {
                //Execute query.
                CoreModule.ExecuteQuery(Context.Guild.Id,
                                        $"update settings set notificationChannel =" +
                                        $" '{_channel.Name}';");

                //Create and set embed object.
                var embed = CoreModule.SimpleEmbed(Color.Green,
                                                   "Set notification's channel completed",
                                                   $"The **channel** {_channel.Mention}" +
                                                   $" has been **set**.");

                //Reply embed.
                await ReplyAsync("", false, embed.Build());

                //Send notification
                CoreModule.SendNotification(Context.Guild.Id,
                                            "Notification's channel changed",
                                            $"{Context.User.Mention} **changed** the Notification's" +
                                            $" channel to {_channel.Mention}.");
            }
        }
Пример #3
0
        GlobalNotificationAsync(string _title, [Remainder] string _description)
        {
            //Create and set the guild iterator.
            var guild = Program.g_client.Guilds.GetEnumerator();

            //Loop guild iterator.
            while (guild.MoveNext())
            {
                //On send messages permission.
                if (guild.
                    Current.
                    CurrentUser.
                    GetPermissions(guild.Current.DefaultChannel).SendMessages)
                {
                    //Send message to default channel.
                    await guild.
                    Current.
                    DefaultChannel.
                    SendMessageAsync("",
                                     false,
                                     CoreModule.SimpleEmbed(Color.Blue,
                                                            _title,
                                                            _description).Build());
                }

                //Delay task.
                await Task.Delay(1000);
            }

            await ReplyAsync("",
                             false,
                             CoreModule.SimpleEmbed(Color.Green,
                                                    "Send global notification completed",
                                                    "The notification has been **`sent`**").Build());
        }
Пример #4
0
        public async Task GetSettingsAsync()
        {
            //Create and set the database connection.
            using (SQLiteConnection dbConnection =
                       new SQLiteConnection($"Data Source = Databases/{Context.Guild.Id}.db;" +
                                            $" Version = 3;")) {
                //Open the connection.
                dbConnection.Open();

                //Create and set query.
                using (SQLiteCommand dbCommand =
                           new SQLiteCommand("SELECT prefix, role, notifications, notificationChannel" +
                                             " FROM settings LIMIT 1;",
                                             dbConnection)) {
                    //Create and set the database reader from the command query.
                    using (SQLiteDataReader dbDataReader = dbCommand.ExecuteReader()) {
                        //Read settings info.
                        dbDataReader.Read();

                        //Create and set socket role.
                        SocketRole role = Context.
                                          Guild.
                                          Roles.
                                          FirstOrDefault(x => x.Name == $"{dbDataReader["role"]}");

                        //Create and set socket text channel.
                        SocketTextChannel channel = Context.
                                                    Guild.
                                                    Channels.
                                                    FirstOrDefault(x => x.Name ==
                                                                   $"{dbDataReader["notificationChannel"]}")
                                                    as SocketTextChannel;

                        //Create and set embed object.
                        var embed = CoreModule.SimpleEmbed(Color.Purple,
                                                           "VGXPBot Settings",
                                                           "These are the settings for this server.");

                        //Create and set embed object.
                        embed.AddField("Prefix",
                                       $"**`{dbDataReader["prefix"]}`**",
                                       false).
                        AddField("Guild Member role",
                                 role == null ? $"{dbDataReader["role"]}" : role.Mention,
                                 true).
                        AddField("Notifications",
                                 $"**`{dbDataReader["notifications"]}`**",
                                 true).
                        AddField("Notification's channel",
                                 channel == null ?
                                 $"{dbDataReader["notificationChannel"]}" : channel.Mention,
                                 true);

                        //Reply embed.
                        await ReplyAsync("", false, embed.Build());
                    }
                }
            }
        }
Пример #5
0
        DeleteDBAsync()
        {
            //Delete database.
            CoreModule.DeleteServerDB(Context.Guild.Id);

            //Reply embed.
            await ReplyAsync("",
                             false,
                             CoreModule.SimpleEmbed(Color.Green,
                                                    "Delete database completed",
                                                    "**Database** has been **deleted**.").Build());
        }
Пример #6
0
        HelpAsync(string _command)
        {
            //Search for the command on the command service.
            var result = Program.g_commands.Search(Context, _command);

            //On command not found.
            if (!result.IsSuccess)
            {
                //Create and set embed object.
                var embed = CoreModule.SimpleEmbed(Color.Red,
                                                   "Command not found",
                                                   $"A command like **`{_command}`**" +
                                                   $" couldn't be found.");

                //Reply embed.
                await ReplyAsync("", false, embed.Build());

                return;
            }

            //Get prefix from guild settings.
            string prefix = CoreModule.GetPrefix(Context.Guild.Id);

            //Create and set embed object.
            var builder = CoreModule.SimpleEmbed(Color.Orange,
                                                 "Bot Commands",
                                                 $"Here are some commands like **`{_command}`**");

            //For each command match on the command search.
            foreach (var match in result.Commands)
            {
                //Create and set command.
                var cmd = match.Command;

                //Add field to embed.
                builder.AddField(string.Join(", ", cmd.Aliases),
                                 $"**Parameters:**" +
                                 $" {string.Join(", ", cmd.Parameters.Select(p => p.Name.Trim('_')))}\n" +
                                 $"**Summary:** {cmd.Summary}",
                                 true);
            }

            //Reply embed.
            await ReplyAsync("", false, builder.Build());
        }
Пример #7
0
        SetNotificationsAsync(bool _boolean)
        {
            //On true.
            if (_boolean)
            {
                //Execute query.
                CoreModule.ExecuteQuery(Context.Guild.Id,
                                        $"UPDATE settings SET notifications = 'On';");

                //Create and set embed object.
                var embed = CoreModule.SimpleEmbed(Color.Green,
                                                   "Set notifications completed",
                                                   $"The **notifications** have been set **`On`**.");

                //Reply embed.
                await ReplyAsync("", false, embed.Build());

                //Send notification
                CoreModule.SendNotification(Context.Guild.Id,
                                            "Notification settings changed",
                                            $"{Context.User.Mention} **changed** the Notification" +
                                            $" settings to **`On`**.");
            }
            //On false.
            else
            {
                //Send notification.
                CoreModule.SendNotification(Context.Guild.Id,
                                            "Notification settings changed",
                                            $"{Context.User.Mention} **changed** the Notification" +
                                            $" settings to **`Off`**.");

                //Execute query.
                CoreModule.ExecuteQuery(Context.Guild.Id,
                                        $"UPDATE settings SET notifications = 'Off';");

                //Create and set embed content.
                var embed = CoreModule.SimpleEmbed(Color.Green,
                                                   "Set notifications completed",
                                                   $"The **notifications** have been set **`Off`**.");

                //Reply embed.
                await ReplyAsync("", false, embed.Build());
            }
        }
Пример #8
0
        StartNewStatsAsync()
        {
            //Execute query.
            CoreModule.ExecuteQuery(Context.Guild.Id, "UPDATE users SET lastXP = actualXP;");

            //Create and set embed object.
            var embed = CoreModule.SimpleEmbed(Color.Green,
                                               "Start new stats completed",
                                               "The **`new stats`** of the database is completed.");

            //Send notification.
            CoreModule.SendNotification(Context.Guild.Id,
                                        "Started new server stats",
                                        $"{Context.User.Mention} **started** new database stats.");

            //Reply embed.
            await ReplyAsync("", false, embed.Build());
        }
Пример #9
0
        SetPrefixAsync(string _prefix)
        {
            //Execute query.
            CoreModule.ExecuteQuery(Context.Guild.Id, $"update settings set prefix = '{_prefix}';");

            //Set embed content.
            var embed = CoreModule.SimpleEmbed(Color.Green,
                                               "Set prefix completed",
                                               $"The **prefix** **`{_prefix}`** has been **set**.");

            //Reply embed.
            await ReplyAsync("", false, embed.Build());

            //Send notification.
            CoreModule.SendNotification(Context.Guild.Id,
                                        "prefix changed",
                                        $"{Context.User.Mention} **changed** the prefix to" +
                                        $" **`{_prefix}`**.");
        }
Пример #10
0
        HelpAsync()
        {
            //Get prefix from guild settings.
            string prefix = CoreModule.GetPrefix(Context.Guild.Id);

            //Create and set embed object.
            var builder = CoreModule.SimpleEmbed(Color.Orange,
                                                 "Bot Commands",
                                                 "These are the commands **you can use**");

            //For each module on command service.
            foreach (var module in Program.g_commands.Modules)
            {
                //Create description string.
                string description = null;

                //For each command on module
                foreach (var cmd in module.Commands)
                {
                    //Create and set precondition.
                    var result = await cmd.CheckPreconditionsAsync(Context);

                    //On precondition success.
                    if (result.IsSuccess)
                    {
                        //Add description for each command.
                        description += $"**`{prefix}`**{cmd.Aliases.First()}" +
                                       $" {string.Join(", ", cmd.Parameters.Select(p => p.Name.Trim('_')))}\n";
                    }
                }

                //On description is not null.
                if (!string.IsNullOrWhiteSpace(description))
                {
                    //Add field to embed object.
                    builder.AddField(module.Name, description, true);
                }
            }

            //Reply embed.
            await ReplyAsync("", false, builder.Build());
        }
Пример #11
0
        RenameUsernameAsync(string _username, [Remainder] SocketGuildUser _user)
        {
            //On user on database.
            if (CoreModule.UserExistsServerDB(Context.Guild.Id, _user.Id))
            {
                //Execute query.
                CoreModule.ExecuteQuery(Context.Guild.Id,
                                        $"UPDATE users SET name = '{_username}'" +
                                        $" where id = {_user.Id};");

                //Set embed object
                var embed = CoreModule.SimpleEmbed(Color.Green,
                                                   "Update completed",
                                                   $"The **update** of the user {_user.Mention}" +
                                                   $" is **completed**.");

                //Reply embed.
                await ReplyAsync("", false, embed.Build());

                //Send notification.
                CoreModule.SendNotification(Context.Guild.Id,
                                            "User username updated",
                                            $"{Context.User.Mention} **updated** the user" +
                                            $" {_user.Mention} database username to" +
                                            $" **`{_username}`**.");
            }
            //On user not on database.
            else
            {
                //Create and set embed content.
                var embed = CoreModule.SimpleEmbed(Color.Red,
                                                   "User not found",
                                                   $"{_user.Mention} doesn't exist on the database," +
                                                   $" **`update aborted`**.");

                //Reply embed.
                await ReplyAsync("", false, embed.Build());
            }
        }
Пример #12
0
        InfoAsync()
        {
            //Create and set embed object.
            var embed = CoreModule.SimpleEmbed(Color.Gold,
                                               "Bot info",
                                               "**Vainglory XP Fame Tracker for Discord**\n\n" +
                                               "This is a simple, yet useful Discord Bot made" +
                                               " on .Net Core with the help of" +
                                               " [Discord.Net](https://github.com/discord-net" +
                                               "/Discord.Net) which makes easier to keep track" +
                                               " of the XP Fame of members on a guild in the" +
                                               " mobile game Vainglory.");

            //Add embed thumbnail.
            embed.WithThumbnailUrl(Context.Client.CurrentUser.GetAvatarUrl());

            //Add embed field.
            embed.AddField("Try it out!",
                           "If you want to give it a try and see for yourself if the bot is what" +
                           " you're looking for your guild, don't hesitate and invite it to" +
                           " your server.\n\n**[Discord bots link](https://top.gg/bot/" +
                           "378327784499445760)**");

            //Add embed field.
            embed.AddField("Contribute!",
                           "Also, if you want to give some feedback or want to work and improve" +
                           " the bot together, you can find me on Discord as **starfoxcom#8144**.");

            //Add embed field.
            embed.AddField("GitHub Repository",
                           "You can find here the link to the project: [VGXPBotCore]" +
                           "(https://github.com/starfoxcom/VGXPBotCore/)");

            //Add embed footer.
            embed.WithFooter("Made with love and a ton of effort by starfoxcom#8144");

            //Reply embed.
            await ReplyAsync("", false, embed.Build());
        }
Пример #13
0
        DeleteAsync([Remainder] SocketGuildUser _user)
        {
            //On user on database.
            if (CoreModule.UserExistsServerDB(Context.Guild.Id, _user.Id))
            {
                //Execute query.
                CoreModule.ExecuteQuery(Context.Guild.Id,
                                        $"DELETE FROM users WHERE id = {_user.Id};");

                //Create and set embed object.
                var embed = CoreModule.SimpleEmbed(Color.Green,
                                                   "Delete completed",
                                                   $"The **delete** of the user" +
                                                   $" {_user.Mention} is **completed**.");

                //Reply embed.
                await ReplyAsync("", false, embed.Build());

                //Send notification.
                CoreModule.SendNotification(Context.Guild.Id,
                                            "User deleted",
                                            $"{Context.User.Mention} **deleted** the user" +
                                            $" {_user.Mention} from the database.");
            }
            //On user not on database.
            else
            {
                //Create and set embed object.
                var embed = CoreModule.SimpleEmbed(Color.Red,
                                                   "User not found",
                                                   $"{_user.Mention} doesn't exist on the database," +
                                                   $" **`delete aborted`**.");

                //Reply embed.
                await ReplyAsync("", false, embed.Build());
            }
        }
Пример #14
0
        SetRoleAsync(SocketRole _role)
        {
            //On server has role.
            if (Context.Guild.Roles.Contains(_role))
            {
                //Execute query.
                CoreModule.ExecuteQuery(Context.Guild.Id,
                                        $"update settings set role = '{_role.Name}';");

                //Create and set embed object.
                var embed = CoreModule.SimpleEmbed(Color.Green,
                                                   "Set role completed",
                                                   $"The **role** {_role.Mention} has been **set**.");

                //Reply embed
                await ReplyAsync("", false, embed.Build());

                //Send notification.
                CoreModule.SendNotification(Context.Guild.Id,
                                            "Member role changed",
                                            $"{Context.User.Mention} **changed** the Guild Member" +
                                            $" **role** to {_role.Mention}.");
            }
        }
Пример #15
0
        GetStatsAsync([Remainder] SocketGuildUser _user)
        {
            //Create and get server member role.
            SocketRole role = CoreModule.GetRole(Context.Guild.Id, Context);

            //On user on database.
            if (CoreModule.UserExistsServerDB(Context.Guild.Id, _user.Id))
            {
                //Create and set the database connection.
                using (SQLiteConnection dbConnection =
                           new SQLiteConnection($"Data Source = Databases/{Context.Guild.Id}.db;" +
                                                $" Version = 3;")) {
                    //Open the connection.
                    dbConnection.Open();

                    //Create and set query.
                    using (SQLiteCommand dbCommand = new SQLiteCommand("SELECT name, region," +
                                                                       " actualXP, lastXP," +
                                                                       " (actualXP - lastXP) as" +
                                                                       " totalXP FROM users " +
                                                                       $"WHERE id = {_user.Id};",
                                                                       dbConnection)) {
                        //Create and set the database reader from the command query.
                        using (SQLiteDataReader dbDataReader = dbCommand.ExecuteReader()) {
                            //Read user stats info.
                            dbDataReader.Read();

                            //Create and set embed object.
                            var embed = CoreModule.SimpleEmbed(Color.Blue,
                                                               $"{_user.Username} stats",
                                                               null);

                            //Add embed fields.
                            embed.AddField("Vainglory username", $"**`{dbDataReader["name"]}`**", true).
                            AddField("Region", $"**`{dbDataReader["region"]}`**", true).
                            AddField("Last XP fame", $"**`{dbDataReader["lastXP"]}`**", true).
                            AddField("Actual XP fame", $"**`{dbDataReader["actualXP"]}`**", true).
                            AddField("Total XP fame", $"**`{dbDataReader["totalXP"]}`**", true);

                            //Add user profile.
                            embed.WithThumbnailUrl(_user.GetAvatarUrl());

                            //Reply embed.
                            await ReplyAsync("", false, embed.Build());
                        }
                    }
                }
            }
            //On user not on database.
            else
            {
                //Create & set embed content.
                var embed = CoreModule.SimpleEmbed(Color.Red,
                                                   "User not found",
                                                   $"{_user.Mention} doesn't exist on the" +
                                                   $" database, **`stats aborted`**.");

                //Reply embed.
                await ReplyAsync("", false, embed.Build());
            }
        }
Пример #16
0
        GetStatsAsync()
        {
            //Create and set socket guild user.
            SocketGuildUser user = Context.User as SocketGuildUser;

            //Create and get the server member role.
            SocketRole role = CoreModule.GetRole(Context.Guild.Id, Context);

            //On socket guild user contains member role.
            if (user.Roles.Contains(role))
            {
                //On user on database.
                if (CoreModule.UserExistsServerDB(Context.Guild.Id, user.Id))
                {
                    //Create and set the database connection.
                    using (SQLiteConnection dbConnection =
                               new SQLiteConnection($"Data Source = Databases/{Context.Guild.Id}.db;" +
                                                    $" Version = 3;")) {
                        //Open the connection.
                        dbConnection.Open();

                        //Create and set query.
                        using (SQLiteCommand dbCommand = new SQLiteCommand("SELECT name, region," +
                                                                           " actualXP, lastXP," +
                                                                           " (actualXP - lastXP) as" +
                                                                           " totalXP FROM users " +
                                                                           $"WHERE id = {user.Id};",
                                                                           dbConnection)) {
                            //Create and set the database reader from the command query.
                            using (SQLiteDataReader dbDataReader = dbCommand.ExecuteReader()) {
                                //Read user stats info.
                                dbDataReader.Read();

                                //Create and set embed object.
                                var embed = CoreModule.SimpleEmbed(Color.Blue, $"{user.Username} stats", null);

                                //Add embed fields.
                                embed.AddField("Vainglory username", $"**`{dbDataReader["name"]}`**", true).
                                AddField("Region", $"**`{dbDataReader["region"]}`**", true).
                                AddField("Last XP fame", $"**`{dbDataReader["lastXP"]}`**", true).
                                AddField("Actual XP fame", $"**`{dbDataReader["actualXP"]}`**", true).
                                AddField("Total XP fame", $"**`{dbDataReader["totalXP"]}`**", true);

                                //Add user profile.
                                embed.WithThumbnailUrl(user.GetAvatarUrl());

                                //Reply embed.
                                await ReplyAsync("", false, embed.Build());
                            }
                        }
                    }
                }
                //On user not on database.
                else
                {
                    //Create and set embed content.
                    var embed = CoreModule.SimpleEmbed(Color.Red,
                                                       "User not found",
                                                       $"{user.Mention} doesn't exist on the" +
                                                       $" database, **`stats aborted`**.");

                    //Reply embed.
                    await ReplyAsync("", false, embed.Build());
                }
            }
            //On socket guild user not contains role.
            else
            {
                //Create embed object.
                EmbedBuilder embed;

                //On role exist.
                if (role != null)
                {
                    //Set embed object.
                    embed = CoreModule.SimpleEmbed(Color.Red,
                                                   "Not a member",
                                                   $"{user.Mention} you're not allowed to use" +
                                                   $" this command, only {role.Mention} is allowed" +
                                                   $" to use it.");
                }
                //Otherwise role don't exist.
                else
                {
                    //Set embed object.
                    embed = CoreModule.SimpleEmbed(Color.Red,
                                                   "Role not set",
                                                   "The **role** to use the commands has" +
                                                   " **not been set**, please use `~setrole`" +
                                                   " to set the role, **`stats aborted`**.");
                }

                //Reply embed.
                await ReplyAsync("", false, embed.Build());
            }
        }
Пример #17
0
        AverageAsync()
        {
            //Create socket user list.
            List <SocketUser> socketUsers = new List <SocketUser>();

            //Create totalXP list.
            List <int> totalXP = new List <int>();

            //Create and set average XP.
            int averageXP = 0;

            //Create and set minimum XP.
            int minimumXP = 0;

            //Create and set the database connection.
            using (SQLiteConnection dbConnection =
                       new SQLiteConnection($"Data Source = Databases/{Context.Guild.Id}.db;" +
                                            $" Version = 3;")) {
                //Open the connection.
                dbConnection.Open();

                //Create and set query.
                using (SQLiteCommand dbCommand = new SQLiteCommand("SELECT id, (actualXP - lastXP)" +
                                                                   " as totalXP FROM users" +
                                                                   " ORDER BY totalXP DESC;",
                                                                   dbConnection)) {
                    //Create and set the database reader from the command query.
                    using (SQLiteDataReader dbDataReader = dbCommand.ExecuteReader()) {
                        //Read users stats info.
                        while (dbDataReader.Read())
                        {
                            //Add user.
                            socketUsers.Add(Context.
                                            Guild.
                                            Users.
                                            FirstOrDefault(x =>
                                                           x.Id ==
                                                           Convert.ToUInt64(dbDataReader["id"])));

                            //Add total XP.
                            totalXP.Add(Convert.ToInt32(dbDataReader["totalXP"]));
                        }
                    }
                }
            }

            //Loop users.
            for (int i = 0; i < socketUsers.Count; ++i)
            {
                //Sum users XP.
                averageXP += totalXP[i];
            }

            //Get average XP.
            averageXP /= socketUsers.Count;

            //Get minimum XP.
            minimumXP = averageXP >> 1;

            //Create and set embed object.
            var average = CoreModule.SimpleEmbed(Color.Blue,
                                                 "Average",
                                                 $"Average XP: **`{averageXP}`**\n" +
                                                 $"Minimum XP: **`{minimumXP}`**");

            //Create and set embed object.
            var Achieved = CoreModule.SimpleEmbed(Color.Green,
                                                  "Achieved",
                                                  $"Users above **`{averageXP}`** XP Fame");

            //Create and set embed object.
            var Achieved2 = CoreModule.SimpleEmbed(Color.Green,
                                                   "Achieved (Cont.)",
                                                   $"Users above {averageXP} XP Fame");

            //Create and set embed object.
            var barelyAchieved = CoreModule.SimpleEmbed(Color.Gold,
                                                        "Barely achieved",
                                                        $"Users below {averageXP} but" +
                                                        $" above {minimumXP} XP Fame");

            //Create and set embed object.
            var barelyAchieved2 = CoreModule.SimpleEmbed(Color.Gold,
                                                         "Barely achieved (Cont.)",
                                                         $"Users below {averageXP} but" +
                                                         $" above {minimumXP} XP Fame");

            //Create and set embed object.
            var notAchieved = CoreModule.SimpleEmbed(Color.Red,
                                                     "Not achieved",
                                                     $"Users below {minimumXP} XP Fame");

            //Create and set embed object.
            var notAchieved2 = CoreModule.SimpleEmbed(Color.Red,
                                                      "Not achieved (Cont.)",
                                                      $"Users below {minimumXP} XP Fame");

            //Create and set user counters.
            int achievedCount       = 0;
            int barelyAchievedCount = 0;
            int notAchievedCount    = 0;

            //Loop users.
            for (int i = 0; i < socketUsers.Count; ++i)
            {
                //On above average.
                if (totalXP[i] >= averageXP)
                {
                    //On less than 25 users.
                    if (achievedCount < 25)
                    {
                        //Add embed field.
                        Achieved.AddField($"{totalXP[i]}", $"{socketUsers[i].Mention}", true);
                    }
                    //On more than 25 users.
                    else
                    {
                        //Add embed field.
                        Achieved2.AddField($"{totalXP[i]}", $"{socketUsers[i].Mention}", true);
                    }

                    //Add to counter.
                    achievedCount++;
                }
                //On below average but above minimum average
                else if (totalXP[i] < averageXP && totalXP[i] >= minimumXP)
                {
                    //On less than 25 users.
                    if (barelyAchievedCount < 25)
                    {
                        //Add embed field.
                        barelyAchieved.AddField($"{totalXP[i]}", $"{socketUsers[i].Mention}", true);
                    }
                    //On more than 25 users.
                    else
                    {
                        //Add embed field.
                        barelyAchieved2.AddField($"{totalXP[i]}", $"{socketUsers[i].Mention}", true);
                    }

                    //Add to counter.
                    barelyAchievedCount++;
                }
                //On below minimum average
                else
                {
                    //On less than 25 users.
                    if (notAchievedCount < 25)
                    {
                        //Add embed field.
                        notAchieved.AddField($"{totalXP[i]}", $"{socketUsers[i].Mention}", true);
                    }
                    //On more than 25 users.
                    else
                    {
                        //Add embed field.
                        notAchieved2.AddField($"{totalXP[i]}", $"{socketUsers[i].Mention}", true);
                    }

                    //Add to counter.
                    notAchievedCount++;
                }
            }

            //Reply embed.
            await ReplyAsync("", false, average.Build());

            //Delay task.
            await Task.Delay(1000);

            //On at least one user achieved the average.
            if (achievedCount > 0)
            {
                //Reply embed.
                await ReplyAsync("", false, Achieved.Build());
            }

            //On more than 25 users achieved the average.
            if (achievedCount > 25)
            {
                //Reply embed.
                await ReplyAsync("", false, Achieved2.Build());
            }

            //Delay task.
            await Task.Delay(1000);

            //On at least one user achieved the minimum average.
            if (barelyAchievedCount > 0)
            {
                //Reply embed.
                await ReplyAsync("", false, barelyAchieved.Build());
            }

            //On more than 25 users achieved the minimum average.
            if (barelyAchievedCount > 25)
            {
                //Reply embed.
                await ReplyAsync("", false, barelyAchieved2.Build());
            }

            //Delay task.
            await Task.Delay(1000);

            //On at least one user not achieved the minimum average.
            if (barelyAchievedCount > 0)
            {
                //Reply embed.
                await ReplyAsync("", false, barelyAchieved.Build());
            }

            //On more than 25 users not achieved the minimum average.
            if (barelyAchievedCount > 25)
            {
                //Reply embed.
                await ReplyAsync("", false, barelyAchieved2.Build());
            }
        }
Пример #18
0
        GoalAsync(int _goal)
        {
            //Create socket user object.
            SocketUser user;

            //Create and set embed object.
            var Achieved = CoreModule.SimpleEmbed(Color.Green,
                                                  "Achieved",
                                                  $"Users who achieved {_goal} XP Fame");

            //Create and set embed object.
            var Achieved2 = CoreModule.SimpleEmbed(Color.Green,
                                                   "Achieved (Cont.)",
                                                   $"Users who achieved {_goal} XP Fame");

            //Create and set embed object.
            var notAchieved = CoreModule.SimpleEmbed(Color.Red,
                                                     "Not achieved",
                                                     $"Users who not achieved {_goal} XP Fame");

            //Create and set embed object.
            var notAchieved2 = CoreModule.SimpleEmbed(Color.Red,
                                                      "Not achieved (Cont.)",
                                                      $"Users who not achieved {_goal} XP Fame");

            //Create and set user counters.
            int achievedCount    = 0;
            int notAchievedCount = 0;

            //Create and set the database connection.
            using (SQLiteConnection dbConnection =
                       new SQLiteConnection($"Data Source = Databases/{Context.Guild.Id}.db;" +
                                            $" Version = 3;")) {
                //Open the connection.
                dbConnection.Open();

                //Create and set query.
                using (SQLiteCommand dbCommand = new SQLiteCommand("SELECT id, (actualXP - lastXP)" +
                                                                   " as totalXP FROM users" +
                                                                   " ORDER BY totalXP DESC;",
                                                                   dbConnection)) {
                    //Create and set the database reader from the command query.
                    using (SQLiteDataReader dbDataReader = dbCommand.ExecuteReader()) {
                        //Read users stats info.
                        while (dbDataReader.Read())
                        {
                            //Get the user id and convert to socketUser.
                            user = Context.
                                   Guild.
                                   Users.
                                   FirstOrDefault(x => x.Id == Convert.ToUInt64(dbDataReader["id"]));

                            //On goal achieved.
                            if (Convert.ToInt32(dbDataReader["totalXP"]) >= _goal)
                            {
                                //On less than 25 users.
                                if (achievedCount < 25)
                                {
                                    //Add content to embed object.
                                    Achieved.AddField($"**`{Convert.ToInt32(dbDataReader["totalXP"])}`**",
                                                      user.Mention,
                                                      true);
                                }
                                //On more that 25 users.
                                else
                                {
                                    //Add content to embed object.
                                    Achieved2.AddField($"**`{Convert.ToInt32(dbDataReader["totalXP"])}`**",
                                                       user.Mention,
                                                       true);
                                }
                                //Add to counter.
                                achievedCount++;
                            }
                            //On goal not achieved.
                            else
                            {
                                //On less than 25 users.
                                if (notAchievedCount < 25)
                                {
                                    //Add content to embed object.
                                    notAchieved.AddField($"**`{Convert.ToInt32(dbDataReader["totalXP"])}`**",
                                                         user.Mention,
                                                         true);
                                }
                                //On more that 25 users.
                                else
                                {
                                    //Add content to embed object.
                                    notAchieved2.AddField($"**`{Convert.ToInt32(dbDataReader["totalXP"])}`**",
                                                          user.Mention,
                                                          true);
                                }
                                //Add to counter.
                                notAchievedCount++;
                            }
                        }
                    }
                }
            }

            //On at least one user achieved the goal.
            if (achievedCount > 0)
            {
                //Reply embed.
                await ReplyAsync("", false, Achieved.Build());
            }

            //On more than 25 users achieved the goal.
            if (achievedCount > 25)
            {
                //Reply embed.
                await ReplyAsync("", false, Achieved2.Build());
            }

            //On at least one user not achieved the goal.
            if (notAchievedCount > 0)
            {
                //Reply embed.
                await ReplyAsync("", false, notAchieved.Build());
            }

            //On more than 25 users not achieved the goal.
            if (notAchievedCount > 25)
            {
                //Reply embed.
                await ReplyAsync("", false, notAchieved2.Build());
            }
        }
Пример #19
0
        ListAsync()
        {
            //Create and set socket user.
            SocketUser socketUser = null;

            //Create and set embed object.
            var embed = CoreModule.SimpleEmbed(Color.Blue, $"Users list", null);

            //Create and set embed object.
            var embed2 = CoreModule.SimpleEmbed(Color.Blue, $"Users list (Cont.)", null);

            //Create and set user counter.
            int userCount = 0;

            //Create and set the database connection.
            using (SQLiteConnection dbConnection =
                       new SQLiteConnection($"Data Source = Databases/{Context.Guild.Id}.db;" +
                                            $" Version = 3;")) {
                //Open the connection.
                dbConnection.Open();

                //Create and set query.
                using (SQLiteCommand dbCommand = new SQLiteCommand("SELECT id, name FROM users ",
                                                                   dbConnection)) {
                    //Create and set the database reader from the command query.
                    using (SQLiteDataReader dbDataReader = dbCommand.ExecuteReader()) {
                        //Read users info.
                        while (dbDataReader.Read())
                        {
                            //Get the user from the server database.
                            socketUser = Context.Guild.Users.FirstOrDefault(x =>
                                                                            x.Id ==
                                                                            Convert.
                                                                            ToUInt64(dbDataReader["id"]));

                            //On less than 25 users.
                            if (userCount < 25)
                            {
                                //Set embed content.
                                embed.AddField($"{dbDataReader["name"]}", $"{socketUser.Mention}", true);
                            }
                            //On more than 25 users.
                            else
                            {
                                //Set embed content.
                                embed2.AddField($"{dbDataReader["name"]}", $"{socketUser.Mention}", true);
                            }

                            //Add to counter.
                            ++userCount;
                        }
                    }
                }
            }

            //Set embed content.
            embed.WithDescription($"The database has a total of **`{userCount}`** users.");

            //Reply embed.
            await ReplyAsync("", false, embed.Build());

            //On users more than 25.
            if (userCount > 25)
            {
                //Reply embed.
                await ReplyAsync("", false, embed2.Build());
            }
        }
Пример #20
0
        SignupAsync(string _username, string _region)
        {
            //Create and set socket guild user.
            SocketGuildUser user = Context.User as SocketGuildUser;

            //Create and set role.
            SocketRole role = CoreModule.GetRole(Context.Guild.Id, Context);

            //On socket guild user contains guild member role.
            if (user.Roles.Contains(role))
            {
                //On user not on database.
                if (!CoreModule.UserExistsServerDB(Context.Guild.Id, user.Id))
                {
                    //Execute query.
                    CoreModule.ExecuteQuery(Context.Guild.Id,
                                            "INSERT INTO users (id,name,region,actualXP,lastXP)" +
                                            $" VALUES ({user.Id},'{_username}','{_region}',0,0);");

                    //Create and set embed object.
                    var embed = CoreModule.SimpleEmbed(Color.Green,
                                                       "Sign up completed",
                                                       $"Your **sign up** is **completed**.");

                    //Reply embed.
                    await ReplyAsync("", false, embed.Build());

                    //Send notification
                    CoreModule.SendNotification(Context.Guild.Id,
                                                "User registered",
                                                $"{user.Mention} **registered** to the database.");
                }
                //On user in database.
                else
                {
                    //Create and set embed object.
                    var embed = CoreModule.SimpleEmbed(Color.Red,
                                                       "User found",
                                                       "You're already on the database," +
                                                       " **`sign up aborted`**.");

                    //Reply embed.
                    await ReplyAsync("", false, embed.Build());
                }
            }
            //On socket guild user not contains role.
            else
            {
                //Create embed object.
                EmbedBuilder embed;

                //On role exist.
                if (role != null)
                {
                    //Set embed object.
                    embed = CoreModule.SimpleEmbed(Color.Red,
                                                   "Not a member",
                                                   $"{user.Mention} you're not allowed to use this" +
                                                   $" command, only {role.Mention} is allowed" +
                                                   $" to use it.");
                }
                //Otherwise role don't exist.
                else
                {
                    //Set embed object.
                    embed = CoreModule.SimpleEmbed(Color.Red,
                                                   "Role not set",
                                                   "The **role** to use the commands has" +
                                                   " **not been set**, please use `~setrole` to set" +
                                                   " the role, **`sign up aborted`**.");
                }

                //Reply embed.
                await ReplyAsync("", false, embed.Build());
            }
        }