Beispiel #1
0
        private static async void LevelUpAsync(IMessage message, User user, int level)
        {
            SocketTextChannel channel = message.Channel as SocketTextChannel;

            if (Program.Guilds.GetValueOrDefault(channel.Guild.Id).LevelupChannel != 0)
            {
                channel = Program.Client.GetChannel(Program.Guilds.GetValueOrDefault(channel.Guild.Id).LevelupChannel) as SocketTextChannel;
            }
            if (!File.Exists($"{Program.Rootdir}\\Users\\LevelUp\\{user.Id}.gif"))
            {
                try { await channel.SendMessageAsync("", false, Embed.GetEmbed($"Congratulations {message.Author.Username} you are now level {level}!", "You havn't uploaded a levelup image yet")); }
                catch { await channel.SendMessageAsync("", false, Embed.GetEmbed("Get Levelup", "Sorry there was an error")); }
                return;
            }

            var tmp = await channel.SendMessageAsync("", false, Embed.GetEmbed($"Congratulations {message.Author.Username} you are now level {level}!", "Loading image..."));

            try
            {
                int globalRank = await Ranks.GetGlobalRank(message.Author.Id);

                int localRank = await Ranks.GetLocalRank(channel.Guild, message.Author.Id);

                if (!File.Exists($"{Program.Rootdir}\\Users\\LevelUp\\{user.Id}Processed.gif") || Program.Users.GetValueOrDefault(user.Id).changed == true)
                {
                    var tmpimg = await LevelUp.MakeLevelAsync(user.Id);

                    if (tmpimg.Length > 8000000)
                    {
                        await tmp.ModifyAsync(x => x.Embed = Embed.GetEmbed($"Congratulations {message.Author.Username} you are now level {level}!", "Levelup image is too big for discord after processing"));

                        GC.Collect();
                        return;
                    }
                    else
                    {
                        File.WriteAllBytes($"{Program.Rootdir}\\Users\\LevelUp\\{message.Author.Id}Processed.gif", tmpimg);
                        Program.Users.GetValueOrDefault(message.Author.Id).changed = false;
                        await Program.SaveUser(user.Id);
                    }
                }
                try
                {
                    await channel.SendFileAsync($"{Program.Rootdir}\\Users\\LevelUp\\{user.Id}Processed.gif", "", false, Embed.GetEmbed($"Congratulations {message.Author} you are now level {level}!", $"You currently rank:\nGuild: {localRank}\nOverall: {globalRank}"));
                }
                catch
                {
                    await tmp.ModifyAsync(x => x.Embed = Embed.GetEmbed("Get Levelup", "Sorry there was an error"));

                    GC.Collect();
                    return;
                }
                await tmp.DeleteAsync();
            }
            catch
            {
                await tmp.ModifyAsync(x => x.Embed = Embed.GetEmbed($"Congratulations {message.Author.Username} you are now level {level}!", "Sorry there was an error"));

                GC.Collect();
                return;
            }
        }
Beispiel #2
0
        public async Task GetLevelUp(IUser UserTag = null)
        {
            if (UserTag == null)
            {
                UserTag = Context.Message.Author as IUser;
            }

            var tmp = await ReplyAsync("", false, Embed.GetEmbed("Get Levelup", "Working..."));

            if (!File.Exists($"{Program.Rootdir}\\Users\\LevelUp\\{UserTag.Id}.gif"))
            {
                await tmp.ModifyAsync(x => x.Embed = Embed.GetEmbed("Get Levelup", "You havn't uploaded a levelup image yet"));

                return;
            }
            else if (File.Exists($"{Program.Rootdir}\\Users\\LevelUp\\{UserTag.Id}Processed.gif") && Program.Users.GetValueOrDefault(UserTag.Id).changed == false)
            {
                try
                {
                    await Context.Message.Channel.SendFileAsync($"{Program.Rootdir}\\Users\\LevelUp\\{UserTag.Id}Processed.gif");
                }
                catch
                {
                    await tmp.ModifyAsync(x => x.Embed = Embed.GetEmbed("Get Levelup", "Sorry there was an error"));

                    GC.Collect();
                    return;
                }
            }
            else
            {
                try
                {
                    var tmpimg = await LevelUp.MakeLevelAsync(UserTag.Id);

                    if (tmpimg.Length > 8000000)
                    {
                        await tmp.ModifyAsync(x => x.Embed = Embed.GetEmbed("Get Levelup", "File too big"));

                        GC.Collect();
                        return;
                    }
                    else
                    {
                        File.WriteAllBytes($"{Program.Rootdir}\\Users\\LevelUp\\{UserTag.Id}Processed.gif", tmpimg);
                        Program.Users.GetValueOrDefault(UserTag.Id).changed = false;
                        await Program.SaveUser(UserTag.Id);

                        await Context.Message.Channel.SendFileAsync($"{Program.Rootdir}\\Users\\LevelUp\\{UserTag.Id}Processed.gif");
                    }
                }
                catch
                {
                    await tmp.ModifyAsync(x => x.Embed = Embed.GetEmbed("Get Levelup", "Sorry there was an error"));

                    GC.Collect();
                    return;
                }
            }

            await tmp.ModifyAsync(x => x.Embed = Embed.GetEmbed("Get Levelup", "Done"));

            System.Threading.Thread.Sleep(5000);
            await tmp.DeleteAsync();

            GC.Collect();
        }