コード例 #1
0
        private async Task OnReactionRemoved(Cacheable<IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3)
        {
            if (arg3.UserId == _client.CurrentUser.Id) return;

            DBConfigSettings config = _db.ConfigSettings.Find("Channels", "Log");
            if (config != null)
            {
                ulong channelId = MakeNumeric(config.Value);
                var message = await arg1.DownloadAsync();

                CommandContext context = new CommandContext(_client, message);
                var channel = await context.Guild.GetTextChannelAsync(channelId);

                await channel.SendMessageAsync($"Reaction: {arg3.Emote} removed from message {message.Id} by <@!{arg3.UserId}>!\r\nLink: https://discordapp.com/channels/{context.Guild.Id}/{message.Channel.Id}/{message.Id}");
            }
        }
コード例 #2
0
        private async Task HandleConfigSubCommandAsync(string sub, string key, string value)
        {
            DBConfigSettings config = _db.ConfigSettings.FirstOrDefault(config => config.Subsection == sub && config.Key == key);

            if (config != null)
            {
                if (string.IsNullOrEmpty(value))
                {
                    _db.Remove(config);
                    await Context.Channel.SendMessageAsync("Deleted DB Setting");

                    await _db.SaveChangesAsync().ConfigureAwait(false);

                    return;
                }

                config.Value            = value;
                _db.Entry(config).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            }
            else
            {
                if (string.IsNullOrEmpty(value))
                {
                    await Context.Channel.SendMessageAsync("New DB Setting cannot have blank value.\r\n" +
                                                           "Syntax: !config section key value\r\n" +
                                                           "Example: !config Channels Log #test-channel");

                    return;
                }

                config = new DBConfigSettings
                {
                    Subsection = sub,
                    Key        = key,
                    Value      = value
                };

                _db.ConfigSettings.Add(config);
            }

            await _db.SaveChangesAsync().ConfigureAwait(false);

            await Context.Channel.SendMessageAsync("Updated DB Setting");
        }