Example #1
0
        public static async Task Main(string[] args)
        {
            MitternachtBot = new MitternachtBot(0, 0);
            await MitternachtBot.RunAsync(args);

            await CreateHostBuilder(args).Build().RunAsync();
        }
Example #2
0
 public Utility(MitternachtBot mitternacht, DiscordSocketClient client, IStatsService stats, IBotCredentials creds)
 {
     _client     = client;
     _stats      = stats;
     _creds      = creds;
     _shardCoord = mitternacht.ShardCoord;
 }
        public CommandHandler(DiscordSocketClient client, DbService db, IBotConfigProvider bc,
                              IEnumerable <GuildConfig> gcs, CommandService commandService, MitternachtBot bot)
        {
            _client         = client;
            _commandService = commandService;
            _bot            = bot;
            _db             = db;

            _log = LogManager.GetCurrentClassLogger();

            _clearUsersOnShortCooldown = new Timer(_ => { UsersOnShortCooldown.Clear(); }, null, GlobalCommandsCooldown,
                                                   GlobalCommandsCooldown);

            DefaultPrefix = bc.BotConfig.DefaultPrefix;
            Prefixes      = gcs
                            .Where(x => x.Prefix != null)
                            .ToDictionary(x => x.GuildId, x => x.Prefix)
                            .ToConcurrent();
        }
Example #4
0
        public StatsService(DiscordSocketClient client, CommandHandler cmdHandler, IBotCredentials creds, MitternachtBot mitternacht)
        {
            _client = client;
            _creds  = creds;
            _sc     = mitternacht.ShardCoord;

            _started = DateTime.UtcNow;
            _client.MessageReceived    += _ => Task.FromResult(Interlocked.Increment(ref _messageCounter));
            cmdHandler.CommandExecuted += (_, e) => Task.FromResult(Interlocked.Increment(ref _commandsRan));

            _client.ChannelCreated += c =>
            {
                var _ = Task.Run(() => {
                    switch (c)
                    {
                    case ITextChannel _:
                        Interlocked.Increment(ref _textChannels);
                        break;

                    case IVoiceChannel _:
                        Interlocked.Increment(ref _voiceChannels);
                        break;
                    }
                });

                return(Task.CompletedTask);
            };

            _client.ChannelDestroyed += c =>
            {
                var _ = Task.Run(() => {
                    switch (c)
                    {
                    case ITextChannel _:
                        Interlocked.Decrement(ref _textChannels);
                        break;

                    case IVoiceChannel _:
                        Interlocked.Decrement(ref _voiceChannels);
                        break;
                    }
                });

                return(Task.CompletedTask);
            };

            _client.GuildAvailable += g =>
            {
                var _ = Task.Run(() =>
                {
                    var tc = g.Channels.Count(cx => cx is ITextChannel);
                    var vc = g.Channels.Count - tc;
                    Interlocked.Add(ref _textChannels, tc);
                    Interlocked.Add(ref _voiceChannels, vc);
                });
                return(Task.CompletedTask);
            };

            _client.JoinedGuild += g =>
            {
                var _ = Task.Run(() =>
                {
                    var tc = g.Channels.Count(cx => cx is ITextChannel);
                    var vc = g.Channels.Count - tc;
                    Interlocked.Add(ref _textChannels, tc);
                    Interlocked.Add(ref _voiceChannels, vc);
                });
                return(Task.CompletedTask);
            };

            _client.GuildUnavailable += g =>
            {
                var _ = Task.Run(() =>
                {
                    var tc = g.Channels.Count(cx => cx is ITextChannel);
                    var vc = g.Channels.Count - tc;
                    Interlocked.Add(ref _textChannels, -tc);
                    Interlocked.Add(ref _voiceChannels, -vc);
                });

                return(Task.CompletedTask);
            };

            _client.LeftGuild += g =>
            {
                var _ = Task.Run(() =>
                {
                    var tc = g.Channels.Count(cx => cx is ITextChannel);
                    var vc = g.Channels.Count - tc;
                    Interlocked.Add(ref _textChannels, -tc);
                    Interlocked.Add(ref _voiceChannels, -vc);
                });

                return(Task.CompletedTask);
            };
        }