Example #1
0
        public async Task ForgetWhoIAm(CommandContext ctx)
        {
            try
            {
                await ctx.TriggerTypingAsync();

                if (!await CanExecute(ctx, Features.Players))
                {
                    return;
                }

                long userId = (long)(ctx?.User?.Id ?? 0UL);
                if (userId == 0)
                {
                    await ctx.RespondAsync($"Sorry, {ctx.User.Mention}. I don't now your Discord User Id! WTF!??!");

                    return;
                }

                var recorder = new DbRecorder(_connectionString);
                recorder.AssociateDiscordUserToPlayer(userId, 0);

                await ctx.RespondAsync($"Done, {ctx.User.Mention}, I no longer know who you are on the game.");

                return;
            }
            catch (Exception ex)
            {
                Log.Error($"{nameof(WhoIAm)}()", ex);
                await ctx.RespondAsync($"Sorry, {ctx.User.Mention}. There was an error... the *Coder* will be notified of `{ex.Message}`.");

                return;
            }
        }
Example #2
0
        public async Task SetWhoIAm(CommandContext ctx,
                                    [Description("The *gamer tag* or *PSN Name*")][RemainingText] string gamerTag = "")
        {
            try
            {
                await ctx.TriggerTypingAsync();

                if (!await CanExecute(ctx, Features.Players))
                {
                    return;
                }

                long userId = (long)(ctx?.User?.Id ?? 0UL);
                if (userId == 0)
                {
                    await ctx.RespondAsync($"Sorry, {ctx.User.Mention}. I don't now your Discord User Id! WTF!??!");

                    return;
                }

                var cfg       = GuildConfiguration.FromGuild(ctx.Guild);
                var plataform = GetPlataform(gamerTag, cfg.Plataform, out gamerTag);

                if (string.IsNullOrWhiteSpace(gamerTag))
                {
                    gamerTag = ctx.User.Username;
                }

                var provider = new DbProvider(_connectionString);

                var playerId = provider.GetPlayerIdByName(plataform, gamerTag);
                if (playerId == null)
                {
                    await ctx.RespondAsync($"Sorry, {ctx.User.Mention}, I do not track `{gamerTag}` yet. Are you a member of a tracked clan? Are you sure about the gamer tag?");

                    return;
                }

                var recorder = new DbRecorder(_connectionString);
                recorder.AssociateDiscordUserToPlayer(userId, playerId.Value);

                await ctx.RespondAsync($"Ok, {ctx.User.Mention}, for now on you can use `me` instead of your full {plataform.TagName()} on " +
                                       $"commands that take it as a parameters. I promisse to never abuse this association, and protected it from use outside of this system. " +
                                       $"If you want me to remove this piece of information use the `ForgetWhoIAm` command.");

                return;
            }
            catch (Exception ex)
            {
                Log.Error($"{nameof(WhoIAm)}()", ex);
                await ctx.RespondAsync($"Sorry, {ctx.User.Mention}. There was an error... the *Coder* will be notified of `{ex.Message}`.");

                return;
            }
        }