예제 #1
0
        private EmbedBuilder CreateConfirmationEmbed(NetflixAccount account, IUser modifiedBy)
        {
            EmbedBuilder embed = new EmbedBuilder()
                                 .AddField("Login", account.Login)
                                 .AddField("Password", account.Password)
                                 .WithColor(_einherjiOptions.EmbedSuccessColor)
                                 .WithThumbnailUrl("https://historia.org.pl/wp-content/uploads/2018/04/netflix-logo.jpg");

            if (modifiedBy != null)
            {
                embed.WithTimestamp(account.ModifiedTimestampUTC)
                .WithFooter($"Last modified by {modifiedBy.Username}#{modifiedBy.Discriminator}", modifiedBy.GetAvatarUrl());
            }
            return(embed);
        }
예제 #2
0
        private async Task CmdRetrieveAccountAsync(SocketCommandContext context, CancellationToken cancellationToken = default)
        {
            using IDisposable logScope = _log.BeginCommandScope(context, this);
            _log.LogDebug("Retrieving Netlix account credentials");
            if (context.IsPrivate)
            {
                _log.LogTrace("Aborting Netflix account credentials retrieving: Group only");
                await SendErrorAsync($"{_einherjiOptions.FailureSymbol} You can't do this in private message.\nGo to {GetAllowedChannelsMentionsText()}.", context.Channel).ConfigureAwait(false);

                return;
            }
            SocketGuildUser user = await context.Guild.GetGuildUserAsync(context.User).ConfigureAwait(false);

            if (!_netflixAccountOptions.CanRetrieve(user))
            {
                _log.LogTrace("Aborting Netflix account credentials retrieving: User not privileged");
                await SendErrorAsync($"{_einherjiOptions.FailureSymbol} You need {GetAllowedRolesMentionsText()} role to do this.", context.Channel).ConfigureAwait(false);

                return;
            }
            if (!_netflixAccountOptions.IsChannelAllowed(context.Channel))
            {
                _log.LogTrace("Aborting Netflix account credentials retrieving: Wrong channel");
                await SendErrorAsync($"You can't do this here.\nGo to {GetAllowedChannelsMentionsText()}.", context.Channel).ConfigureAwait(false);

                return;
            }

            // retrieve info from store
            NetflixAccount account = await _netflixAccountStore.GetAsync(cancellationToken).ConfigureAwait(false);

            // create message
            IUser modifiedByUser = null;

            if (account.ModifiedByID != null)
            {
                modifiedByUser = await context.Client.GetUserAsync(account.ModifiedByID.Value).ConfigureAwait(false);
            }
            EmbedBuilder    embed   = CreateConfirmationEmbed(account, modifiedByUser);
            string          text    = this.IsAutoRemoving ? GetAutoremoveText() : null;
            RestUserMessage sentMsg = await context.ReplyAsync(text, false, embed.Build(), cancellationToken).ConfigureAwait(false);

            // auto remove
            if (this.IsAutoRemoving)
            {
                RemoveMessagesDelayed(_netflixAccountOptions.AutoRemoveDelay, cancellationToken, sentMsg, context.Message);
            }
        }
예제 #3
0
        private async Task CmdUpdateAccountAsync(SocketCommandContext context, Match match, CancellationToken cancellationToken = default)
        {
            using IDisposable logScope = _log.BeginCommandScope(context, this);
            _log.LogDebug("Updating Netlix account credentials");
            if (context.IsPrivate)
            {
                _log.LogTrace("Aborting Netflix account credentials updating: Group only");
                await SendErrorAsync($"{_einherjiOptions.FailureSymbol} You can't do this in private message.\nGo to {GetAllowedChannelsMentionsText()}.", context.Channel).ConfigureAwait(false);

                return;
            }
            SocketGuildUser user = await context.Guild.GetGuildUserAsync(context.User).ConfigureAwait(false);

            if (!_netflixAccountOptions.CanModify(user))
            {
                _log.LogTrace("Aborting Netflix account credentials updating: User not privileged");
                await SendErrorAsync($"{_einherjiOptions.FailureSymbol} You need {GetAllowedRolesMentionsText()} role to do this.", context.Channel).ConfigureAwait(false);

                return;
            }
            if (!_netflixAccountOptions.IsChannelAllowed(context.Channel))
            {
                _log.LogTrace("Aborting Netflix account credentials updating: Wrong channel");
                await SendErrorAsync($"You can't do this here.\nGo to {GetAllowedChannelsMentionsText()}.", context.Channel).ConfigureAwait(false);

                return;
            }

            // retrieve info from store
            NetflixAccount account = await _netflixAccountStore.GetAsync(cancellationToken).ConfigureAwait(false);

            // update and save
            SetMode mode         = StringToSetMode(match.Groups[1].Value);
            string  value        = match.Groups[2].Value;
            string  responseText = null;

            if (mode == SetMode.Login)
            {
                account.SetLogin(value, context.User.Id);
                responseText = $"{_einherjiOptions.SuccessSymbol} You have set Netflix account login to `{value}`.";
            }
            if (mode == SetMode.Password)
            {
                account.SetPassword(value, context.User.Id);
                responseText = $"{_einherjiOptions.SuccessSymbol} You have set Netflix account password to `{value}`.";
            }

            await _netflixAccountStore.SetAsync(account, cancellationToken).ConfigureAwait(false);

            // create message
            EmbedBuilder embed = CreateConfirmationEmbed(account, context.User);

            embed.WithDescription(responseText);
            string          text    = this.IsAutoRemoving ? GetAutoremoveText() : null;
            RestUserMessage sentMsg = await context.ReplyAsync(text, false, embed.Build(), cancellationToken).ConfigureAwait(false);

            // auto remove
            if (this.IsAutoRemoving)
            {
                RemoveMessagesDelayed(_netflixAccountOptions.AutoRemoveDelay, cancellationToken, sentMsg, context.Message);
            }
        }