Пример #1
0
 public CommandHandlerService(DiscordSocketClient client, CommandService commands, IServiceProvider services)
 {
     _commands   = commands;
     _client     = client;
     _services   = services;
     _expservice = new ExperienceService();
     ratelimit   = new Discord.Addons.Preconditions.RatelimitAttribute(1, exp_cooldown, Discord.Addons.Preconditions.Measure.Minutes);
 }
Пример #2
0
        public async Task AwardExperienceAsync(SocketMessage messageParam)
        {
            // Don't process the message if it was a system message, or if it was a DM
            var message = messageParam as SocketUserMessage;

            if (message == null)
            {
                return;
            }

            // Don't process the message if it was supposed to be a command
            int argPos = 0;

            if (message.HasCharPrefix(cmd_prefix, ref argPos))
            {
                return;
            }

            var user = message.Author;

            if (user.IsBot)
            {
                return;
            }
            var channel = message.Channel as SocketGuildChannel;

            if (channel == null)
            {
                return;
            }

            var context = new SocketCommandContext(_client, message);

            if (CharacterUtilityService.CharacterExists(user))
            {
                byte level = ExperienceService.GetCharacterLevel(user);

                // passing the 5 minute check
                if (ratelimit.BastardizedCheckPermissionsAsync(context, _services) && level < 50)
                {
                    ExperienceService.AwardExp(user);
                }

                byte newLevel = ExperienceService.GetCharacterLevel(user);
                if (newLevel > level)
                {
                    await context.Channel.SendMessageAsync(user.Mention + " is now level " + newLevel + "!");

                    await ExperienceService.CharacterLevelUp(user);
                }
            }
            else
            {
                return;
            }
        }