Ejemplo n.º 1
0
        private async Task HandleCommandAsync(SocketMessage arg)
        {
            SocketUserMessage msg = arg as SocketUserMessage;

            if (msg == null || arg.Author.IsBot)
            {
                return;
            }
            int pos = 0;

            if (msg.HasMentionPrefix(client.CurrentUser, ref pos) || msg.HasStringPrefix("s.", ref pos))
            {
                if (arg.Channel as ITextChannel == null)
                {
                    await arg.Channel.SendMessageAsync("I can't answer to commands in private message.");

                    return;
                }
                SocketCommandContext context = new SocketCommandContext(client, msg);
                IResult res = await commands.ExecuteAsync(context, pos, null);

                if (res.IsSuccess && websiteCredentials != null)
                {
                    await Utils.WebsiteUpdate("SkytaleBot", websiteCredentials.Item1, websiteCredentials.Item2, "nbMsgs", "1");
                }
                else if (!res.IsSuccess && msg.Content.Length > 0)
                {
                    await SendReport(await Features.Moderation.MessageCheck.CheckMessageText(TClient.TranslateText(msg.Content, "en").TranslatedText), ((ITextChannel)msg.Channel).Guild, msg.Author, msg.Content, msg.Id, msg.Channel.Id);
                }
            }
            else if (msg.Content.Length > 0)
            {
                await SendReport(await Features.Moderation.MessageCheck.CheckMessageText(TClient.TranslateText(msg.Content, "en").TranslatedText), ((ITextChannel)msg.Channel).Guild, msg.Author, msg.Content, msg.Id, msg.Channel.Id);
            }
            if (msg.Content.Length > 0)
            {
                if (await BotDb.CanDoXp(msg.Author.Id) < 0)
                {
                    int value = Rand.Next(2, 4);
                    int oldXp = await BotDb.GetXp(msg.Author.Id);

                    int newLevel = Modules.Leveling.GetLevelFromXp(oldXp + value);
                    if (Modules.Leveling.GetLevelFromXp(oldXp) < newLevel)
                    {
                        await msg.AddReactionAsync(new Emoji("🎉"));

                        IGuild guild = ((ITextChannel)msg.Channel).Guild;
                        await msg.Author.SendMessageAsync("Félicitation, vous avez atteint le niveau " + newLevel + " dans " + guild.Name + " !");

                        ulong id = await BotDb.GetRoleForLevel(guild.Id, newLevel);

                        if (id != 0)
                        {
                            await((IGuildUser)msg.Author).AddRoleAsync(guild.GetRole(id));
                        }
                    }
                    await BotDb.GainXp(msg.Author.Id, value);

                    await BotDb.ResetXp(msg.Author.Id);
                }
            }
        }