예제 #1
0
            public async Task globalrank([OptionalAttribute] IGuildUser user)
            {
                if (user == null)
                {
                    user = Context.User as IGuildUser;
                }
                var results = XpService.getglobalxp(user);
                var level   = XpService.checkLevel(results.Value);
                var avatar  = user.GetAvatarUrl();

                if (avatar == null)
                {
                    avatar = "https://cdn.discordapp.com/embed/avatars/0.png";
                }
                if (avatar.Contains("/a_"))
                {
                    avatar = $"{avatar.Remove(avatar.Length - 12)}gif?size=128";
                }
                var color = new Color(255, 239, 0);

                var embed = new EmbedBuilder()
                            .WithThumbnailUrl(avatar)
                            .WithColor(color)
                            .WithTitle($"{user.Username}'s global rank")
                            .AddField(x => { x.Name = "Position:"; x.Value = results.Key; x.WithIsInline(true); })
                            .AddField(x => { x.Name = "level:"; x.Value = level.Key; x.WithIsInline(true); })
                            .AddField(x => { x.Name = "Exp:"; x.Value = $"{results.Value}/{level.Value}"; x.WithIsInline(true); })
                            .Build();

                await Context.Channel.SendMessageAsync("", false, embed);
            }
예제 #2
0
            public async Task serverleaders()
            {
                var exp = Justibot.Loader.LoadPerm(Context.User as IGuildUser, "EXP");

                if (exp.Item1 == true)
                {
                    var leading = XpService.serverLeads(Context).Result;
                    int i       = 1;
                    KeyValuePair <int, int> level;
                    string leaders = "";
                    foreach (var leader in leading)
                    {
                        level    = XpService.checkLevel(leader.Value);
                        leaders += $"{i}: {(await Context.Client.GetGuildAsync(leader.Key) as IGuild).Name} \t lvl: {level.Key} \t {leader.Value}/{level.Value}exp \n";
                        i++;
                    }
                    var color = new Color(255, 239, 0);

                    var embed = new EmbedBuilder()
                                .WithTitle($"Server Leaderboard")
                                .WithDescription(leaders)
                                .WithColor(color)
                                .Build();

                    await Context.Channel.SendMessageAsync("", false, embed);
                }
            }
예제 #3
0
            public async Task globalleaders()
            {
                var leading = XpService.globalLeads(Context).Result;
                int i       = 1;
                KeyValuePair <int, int> level;
                string     leaders = "";
                var        guildys = (Context.Client as DiscordSocketClient).Guilds;
                IGuildUser auser   = null;

                foreach (var leader in leading)
                {
                    foreach (var g in guildys)
                    {
                        auser = (await(g as IGuild).GetUserAsync(leader.Key));
                        if (auser != null)
                        {
                            break;
                        }
                    }
                    level    = XpService.checkLevel(leader.Value);
                    leaders += $"{i}: {auser.Username} \t lvl: {level.Key} \t {leader.Value}/{level.Value}exp \n";
                    i++;
                }
                var color = new Color(255, 239, 0);

                var embed = new EmbedBuilder()
                            .WithTitle($"Global Leaderboard")
                            .WithDescription(leaders)
                            .WithColor(color)
                            .Build();

                await Context.Channel.SendMessageAsync("", false, embed);
            }
예제 #4
0
        public async Task listrewards()
        {
            var exp = Justibot.Loader.LoadPerm(Context.User as IGuildUser, "EXP");

            if (exp.Item1 == true)
            {
                var    rewards = XpService.rewardlist(Context.User as IGuildUser);
                string lists   = "";
                foreach (var award in rewards)
                {
                    string role = Context.Guild.GetRole(award.Item1).Name;
                    lists += $"**{role}** is given at level: **{award.Item2}**! \n";
                }

                var color = new Color(255, 239, 0);

                var embed = new EmbedBuilder()
                            .WithTitle($"{Context.Guild.Name} rewards")
                            .WithDescription(lists)
                            .WithColor(color)
                            .Build();

                await Context.Channel.SendMessageAsync("", false, embed);
            }
        }
예제 #5
0
            public async Task serverrank()
            {
                var exp = Justibot.Loader.LoadPerm(Context.User as IGuildUser, "EXP");

                if (exp.Item1 == true)
                {
                    var guild   = Context.Guild;
                    var results = XpService.getserverxp(guild);
                    var level   = XpService.checkLevel(results.Value);
                    var avatar  = guild.IconUrl;
                    if (avatar == null)
                    {
                        avatar = "https://cdn.discordapp.com/embed/avatars/0.png";
                    }
                    if (avatar.Contains("/a_"))
                    {
                        avatar = $"{avatar.Remove(avatar.Length - 12)}gif?size=128";
                    }
                    var color = new Color(255, 239, 0);

                    var embed = new EmbedBuilder()
                                .WithThumbnailUrl(avatar)
                                .WithColor(color)
                                .WithTitle($"{guild.Name}'s rank")
                                .AddField(x => { x.Name = "Position:"; x.Value = results.Key; x.WithIsInline(true); })
                                .AddField(x => { x.Name = "level:"; x.Value = level.Key; x.WithIsInline(true); })
                                .AddField(x => { x.Name = "Exp:"; x.Value = $"{results.Value}/{level.Value}"; x.WithIsInline(true); })
                                .Build();

                    await Context.Channel.SendMessageAsync("", false, embed);
                }
            }
예제 #6
0
        public async Task resetlevels()
        {
            var exp = Justibot.Loader.LoadPerm(Context.User as IGuildUser, "EXP");

            if (exp.Item1 == true)
            {
                IGuildUser activeuser  = Context.User as IGuildUser;
                var        application = await Context.Client.GetApplicationInfoAsync();

                if (activeuser.GuildPermissions.Has(GuildPermission.Administrator) || activeuser.Id == application.Owner.Id)
                {
                    Justibot.Saver.resetxp(activeuser);
                    XpService.wipeserver(Context.Guild);
                }
            }
        }
예제 #7
0
        public async Task setreward(IRole role, int lvl)
        {
            var exp = Justibot.Loader.LoadPerm(Context.User as IGuildUser, "EXP");

            if (exp.Item1 == true)
            {
                var application = await Context.Client.GetApplicationInfoAsync();

                var activeuser = Context.User as IGuildUser;
                if (activeuser.GuildPermissions.Has(GuildPermission.Administrator) || activeuser.Id == application.Owner.Id)
                {
                    XpService.addReward(role, activeuser, lvl);
                    Justibot.Saver.saveReward(activeuser, role.Id, lvl);
                    await ReplyAsync($"{activeuser.Mention} set the role **{role.Name}** as a level {lvl} reward.");
                }
            }
        }
예제 #8
0
        public async Task removereward(IRole role)
        {
            var exp = Justibot.Loader.LoadPerm(Context.User as IGuildUser, "EXP");

            if (exp.Item1 == true)
            {
                var application = await Context.Client.GetApplicationInfoAsync();

                var activeuser = Context.User as IGuildUser;
                if (activeuser.GuildPermissions.Has(GuildPermission.Administrator) || activeuser.Id == application.Owner.Id)
                {
                    XpService.removeReward(role, activeuser);
                    bool check = Justibot.Saver.deleteReward(activeuser, role.Id);
                    if (check)
                    {
                        await ReplyAsync($"{activeuser.Mention} removed the role **{role.Name}** from the rewards list.");
                    }
                    else
                    {
                        await ReplyAsync($"Failed to remove. {role.Name} not found in reward list.");
                    }
                }
            }
        }
예제 #9
0
파일: Club.cs 프로젝트: bazettfraga/Illyous
 public Club(XpService xps, DiscordSocketClient client)
 {
     _xps    = xps;
     _client = client;
 }
예제 #10
0
        public async Task Start()
        {
            Configuration.configure();

            //create client and add what serverity of information to log
            client = new DiscordSocketClient(new DiscordSocketConfig()
            {
                LogLevel            = LogSeverity.Info,
                ExclusiveBulkDelete = false,
            });

            //create template for logged messages
            client.Log += (message) =>
            {
                Console.WriteLine(message.ToString());
                return(Task.CompletedTask);
            };

            //when client is ready, load important information to memory for quick access and set game to help message
            client.Ready += async() =>
            {
                await client.SetGameAsync("Use +help");

                PrefixService.LoadPrefixs(client);
                WelcomeService.LoadWelcomes(client);
                LeavingService.Loadleaving(client);
                XpService.Loadxps(client);

                //start timer for xp module
                XpService.timerStart();

                //if version from data file has changed, reset update time (used to track time since update)
                if (Justibot.Loader.checkUpdate().Value != Justibot.Data.version)
                {
                    Justibot.Saver.addVersion(DateTime.Now, Justibot.Data.version);
                }
            };

            //log the client into discord with the bot token
            await client.LoginAsync(TokenType.Bot, Configuration.config.Token);

            await client.StartAsync();

            //when a user joins a guild, check appropriate permissions and react accordingly
            client.UserJoined += async(user) =>
            {
                //check welcome module
                var results = Justibot.Loader.LoadPerm(user, "WELCOME");
                var guild   = user.Guild as IGuild;
                //if welcome module enabled send message
                if (results.Item1 == true)
                {
                    ulong result2 = results.Item2;
                    //get designated channel for welcome messages
                    SocketTextChannel welcomeChannel = user.Guild.GetChannel(result2) as SocketTextChannel;

                    //if welcome message is available for guild use it, otherwise use default
                    bool check = welcomedict.welcomes.TryGetValue(guild.Id, out string welcome);
                    if (!check)
                    {
                        welcome = "Welcome, **[user]** has joined **[server]!!!** \n" +
                                  "Have a good time!!!";
                    }
                    //fill in placeholder text with appropriate information
                    welcome = welcome.Replace("[user]", user.Username);
                    welcome = welcome.Replace("[server]", guild.Name);

                    //if permission argument is plain send message in plain text otherwise send in embeded message
                    if (results.Item3 == "PLAIN")
                    {
                        await welcomeChannel.SendMessageAsync(welcome);
                    }
                    else
                    {
                        string avatar = user.GetAvatarUrl();
                        if (avatar == null)
                        {
                            avatar = "https://cdn.discordapp.com/embed/avatars/0.png";
                        }
                        Color color = new Color(0, 255, 0);
                        if (avatar.Contains("/a_"))
                        {
                            avatar = $"{avatar.Remove(avatar.Length - 12)}gif?size=128";
                        }

                        var embed = new EmbedBuilder()
                                    .WithColor(color)
                                    .WithTitle($"{Format.Bold($"{client.CurrentUser.Username}:")}")
                                    .WithDescription(welcome)
                                    .WithThumbnailUrl(avatar)
                                    .Build();

                        await welcomeChannel.SendMessageAsync(user.Mention, false, embed);
                    }
                }
                //if joining role is enabled give new user the role
                var joinRoles = Justibot.Loader.LoadPerm(user, "JOINROLE");
                if (joinRoles.Item1 == true)
                {
                    IRole joinerRole = user.Guild.GetRole(joinRoles.Item2) as IRole;
                    await user.AddRoleAsync(joinerRole);
                }
                //if log permission enabled send message to log channel
                var results2 = Justibot.Loader.LoadPerm(user, "LOG");
                if (results2.Item1 == true)
                {
                    ulong             result2    = results2.Item2;
                    SocketTextChannel logChannel = user.Guild.GetChannel(result2) as SocketTextChannel;

                    if (results2.Item3 == "PLAIN")
                    {
                        await logChannel.SendMessageAsync($"{Format.Bold($"{user.Username}")}#{user.Discriminator}, ID:<{user.Id}> has joined the server. \n" +
                                                          $"There are now {user.Guild.MemberCount} members.");
                    }
                    else
                    {
                        string avatar = user.GetAvatarUrl();
                        Color  color  = new Color(0, 255, 0);
                        //if no avatar available use deafult
                        if (avatar == null)
                        {
                            avatar = "https://cdn.discordapp.com/embed/avatars/0.png";
                        }
                        //check if avatar is gif (gif avatars contain /a_ in their URLs
                        if (avatar.Contains("/a_"))
                        {
                            avatar = $"{avatar.Remove(avatar.Length - 12)}gif?size=128";
                        }

                        var embed = new EmbedBuilder()
                                    .WithColor(color)
                                    .WithTitle($"{Format.Bold($"{client.CurrentUser.Username}:")}")
                                    .WithDescription($"{Format.Bold($"{user.Username}")}#{user.Discriminator}, ID:<{user.Id}> has joined the server. \n" +
                                                     $"There are now {user.Guild.MemberCount} members.")
                                    .WithThumbnailUrl(avatar)
                                    .Build();

                        await logChannel.SendMessageAsync("", false, embed);
                    }
                }
                //if bunker mode is enabled on server instantly kick new user
                if (Settings.bunker.Contains(guild.Id))
                {
                    await user.Guild.DefaultChannel.SendMessageAsync($"{Format.Bold($"{user.Username}")} was kicked by bunker mode!");

                    await user.KickAsync("Bunker mode enabled");
                }
            };

            //when user leaves guild check appropriate permissions and act accordingly
            client.UserLeft += async(user) =>
            {
                //check leaving permission
                var results = Justibot.Loader.LoadPerm(user, "LEAVING");
                if (results.Item1 == true)
                {
                    ulong result2 = results.Item2;
                    var   guild   = user.Guild as IGuild;
                    //get channel to send leaving message to
                    SocketTextChannel leaveChannel = user.Guild.GetChannel(result2) as SocketTextChannel;

                    //if leaving message available set it, else use default message
                    bool check = welcomedict.leaves.TryGetValue(guild.Id, out string leave);
                    if (!check)
                    {
                        leave = "**[mention]** has left **[server]**, goodbye.";
                    }
                    //replace placeholder text with appropriate items
                    leave = leave.Replace("[user]", user.Username);
                    leave = leave.Replace("[mention]", user.Mention);
                    leave = leave.Replace("[server]", guild.Name);

                    //if leaving permission argument is plain, send plain text otherwise send as an embed message
                    if (results.Item3 == "PLAIN")
                    {
                        await leaveChannel.SendMessageAsync(leave);
                    }
                    else
                    {
                        string avatar = user.GetAvatarUrl();
                        Color  color  = new Color(255, 0, 0);
                        //if no avatar available use deafult
                        if (avatar == null)
                        {
                            avatar = "https://cdn.discordapp.com/embed/avatars/0.png";
                        }
                        //check if avatar is gif (gif avatars contain /a_ in their URLs
                        if (avatar.Contains("/a_"))
                        {
                            avatar = $"{avatar.Remove(avatar.Length - 12)}gif?size=128";
                        }

                        var embed = new EmbedBuilder()
                                    .WithColor(color)
                                    .WithTitle($"{Format.Bold($"{client.CurrentUser.Username}:")}")
                                    .WithDescription(leave)
                                    .WithThumbnailUrl(avatar)
                                    .Build();

                        await leaveChannel.SendMessageAsync("", false, embed);
                    }
                }

                //if log module is enabled, send message to log channel bassed on argument (plain text or embed)
                var results2 = Justibot.Loader.LoadPerm(user, "LOG");
                if (results2.Item1 == true)
                {
                    ulong             result2        = results2.Item2;
                    var               guild          = user.Guild as IGuild;
                    SocketTextChannel welcomeChannel = user.Guild.GetChannel(result2) as SocketTextChannel;

                    if (results2.Item3 == "PLAIN")
                    {
                        await welcomeChannel.SendMessageAsync($"{Format.Bold($"{user.Username}")}#{user.Discriminator}, ID:<{user.Id}> has left the server. \n" +
                                                              $"There are now {user.Guild.MemberCount} members.");
                    }
                    else
                    {
                        string avatar = user.GetAvatarUrl();
                        Color  color  = new Color(255, 0, 0);
                        //if no avatar available use deafult
                        if (avatar == null)
                        {
                            avatar = "https://cdn.discordapp.com/embed/avatars/0.png";
                        }
                        //check if avatar is gif (gif avatars contain /a_ in their URLs
                        if (avatar.Contains("/a_"))
                        {
                            avatar = $"{avatar.Remove(avatar.Length - 12)}gif?size=128";
                        }

                        var embed = new EmbedBuilder()
                                    .WithColor(color)
                                    .WithTitle($"{Format.Bold($"{client.CurrentUser.Username}:")}")
                                    .WithDescription($"{Format.Bold($"{user.Username}")}#{user.Discriminator}, ID:<{user.Id}> has left the server. \n" +
                                                     $"There are now {user.Guild.MemberCount} members.")
                                    .WithThumbnailUrl(avatar)
                                    .Build();

                        await welcomeChannel.SendMessageAsync("", false, embed);
                    }
                }
            };

            //if user messages a channel the bot can see, check permissions
            client.MessageReceived += async(message) =>
            {
                var guild = (message.Channel as SocketTextChannel)?.Guild;
                var user  = (message.Author as IGuildUser);
                if (guild != null)
                {
                    //if user isnt bot, give xp to user
                    if (user.IsBot == false)
                    {
                        var guild2 = guild as IGuild;
                        XpService.AddXp(user, guild2);
                    }
                    //if message contains a discord invite link, check if use has manage guild permissions
                    if ((message.ToString().ToUpper()).Contains("DISCORD.GG/") && (!(user.IsBot)))
                    {
                        //if user does not have manage guild permission check if advertising module is enabled
                        if (!(user.GuildPermissions.Has(GuildPermission.ManageGuild)) || !(Justibot.Loader.isStaff(user)))
                        {
                            var results = Justibot.Loader.LoadPerm(user, "ADVERTISING");
                            if (results.Item1 == true)
                            {
                                //if module is set to delete, remove message and asks user to not advertise in the server
                                ulong result2 = results.Item2;
                                if (results.Item3 == "DELETE")
                                {
                                    await message.DeleteAsync();

                                    var response = await message.Channel.SendMessageAsync($"{user.Mention} please do not advertise in this server");

                                    respond(response);
                                }
                                //if module is set to repost, send copy of message to advertising channel and ask user to only post advertisements to channel
                                else if (results.Item3 == "REPOST")
                                {
                                    SocketTextChannel advertisingChannel = guild.GetChannel(result2) as SocketTextChannel;
                                    if (message.Channel != advertisingChannel)
                                    {
                                        await advertisingChannel.SendMessageAsync($"{user.Mention} advertised message: \n{message.ToString()}");

                                        await message.DeleteAsync();

                                        var response = await message.Channel.SendMessageAsync($"{user.Mention} please keep advertising to {advertisingChannel.Mention}, your message has been shifted there.");

                                        respond(response);
                                    }
                                }
                            }
                        }
                    }
                }
            };
            //initialize commands and commandhandler
            handler = new CommandHandler();
            await handler.InitCommands(client);

            //prevent application shutdown
            await Task.Delay(-1);
        }
예제 #11
0
 public Club(XpService xps)
 {
     _xps = xps;
 }
예제 #12
0
 public XpController(XpService xpService)
 {
     _xpService = xpService;
 }