Beispiel #1
0
        public async Task BlockDMs(
            CommandContext context,
            [Description("Block DMs (true) or allow them (false)")]
            bool block = true
            )
        {
            var guild = context.GetGuild();

            UserMessageSettings userConfig = _dbContext.GetMessageSettings(guild.Id, context.User.Id);

            if (userConfig == null)
            {
                userConfig = new UserMessageSettings()
                {
                    GuildId  = guild.Id,
                    UserId   = context.User.Id,
                    BlockDMs = block
                };
                _dbContext.SetMessageSettings(userConfig);
            }
            else
            {
                userConfig.BlockDMs = block;
                _dbContext.SetMessageSettings(userConfig);
            }
            if (userConfig.BlockDMs)
            {
                await context.RespondAsync($"You will no longer receive DMs via the `send_dm` command.");
            }
            else
            {
                await context.RespondAsync($"You can now receive DMs via the `send_dm` command again.");
            }
        }
Beispiel #2
0
        public async Task SendDM(
            CommandContext context,
            [Description("Name or @mention of the user you want to message.")]
            string receiver,
            [Description("Your message")]
            [RemainingText] string message
            )
        {
            if (context.User.IsBot)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(message))
            {
                await context.RespondAsync("You must specify a message.");

                return;
            }

            var guild           = context.GetGuild();
            var receivingMember = guild.FindMember(receiver);

            if (receivingMember == null)
            {
                await context.RespondAsync($"Could not find '{receiver}'.");

                return;
            }
            else if (receivingMember.IsBot)
            {
                await context.RespondAsync($"You can't message bots with this command.");

                return;
            }
            else if (receivingMember.Id == context.User.Id)
            {
                return;
            }

            UserMessageSettings receiverSettings = this._dbContext.GetMessageSettings(guild.Id, receivingMember.Id);

            if (receiverSettings != null && receiverSettings.BlockDMs)
            {
                await context.RespondAsync($"Can't send your message to {receiver}.");
            }
            else
            {
                var channel = await receivingMember.CreateDmChannelAsync();

                await channel.SendMessageAsync($"Anonymous says: {message}");
            }
        }