Exemplo n.º 1
0
 public static void Log(LogSeverity severity, string source, string message)
 {
     PrettyConsole.NewLine($"{DateTimeOffset.Now.ToString("hh:mm:ss")} ", ConsoleColor.DarkGray);
     PrettyConsole.Append($"[{severity}] ", ConsoleColor.Red);
     PrettyConsole.Append($"{source}: ", ConsoleColor.DarkGreen);
     PrettyConsole.Append(message, ConsoleColor.White);
 }
Exemplo n.º 2
0
        static DEABot()
        {
            try
            {
                using (StreamReader file = File.OpenText(@"Credentials.json"))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    Credentials = (Credentials)serializer.Deserialize(file, typeof(Credentials));
                }
            }
            catch (IOException e)
            {
                PrettyConsole.Log(LogSeverity.Error, "Error while loading up Credentials.json, please fix this issue and restart the bot", e.Message);
                Console.ReadKey();
                Environment.Exit(0);
            }

            DBClient = new MongoClient(Credentials.MongoDBConnectionString);
            Database = DBClient.GetDatabase("dea");

            Guilds = Database.GetCollection <Guild>("guilds");
            Users  = Database.GetCollection <User>("users");
            Gangs  = Database.GetCollection <Gang>("gangs");
            Mutes  = Database.GetCollection <Mute>("mutes");

            GuildUpdateBuilder = Builders <Guild> .Update;
            UserUpdateBuilder  = Builders <User> .Update;
            GangUpdateBuilder  = Builders <Gang> .Update;
        }
Exemplo n.º 3
0
 static DEABot()
 {
     try
     {
         using (StreamReader file = File.OpenText(@"..\..\Credentials.json"))
         {
             JsonSerializer serializer = new JsonSerializer();
             Credentials = (Credentials)serializer.Deserialize(file, typeof(Credentials));
         }
     }
     catch (IOException e)
     {
         PrettyConsole.Log(LogSeverity.Error, "Error while loading up Credentials.json, please fix this issue and restart the bot", e.Message);
     }
 }
Exemplo n.º 4
0
        public async Task RunAsync(params string[] args)
        {
            PrettyConsole.NewLine("===   DEA   ===");
            PrettyConsole.NewLine();

            Client = new DiscordSocketClient(new DiscordSocketConfig()
            {
                LogLevel         = LogSeverity.Error,
                MessageCacheSize = 10,
                TotalShards      = Credentials.ShardCount,
                //AlwaysDownloadUsers = true,
            });

            Client.Log += (l)
                          => Task.Run(()
                                      => PrettyConsole.Log(l.Severity, l.Source, l.Exception?.ToString() ?? l.Message));

            CommandService = new CommandService(new CommandServiceConfig()
            {
                CaseSensitiveCommands = false,
                DefaultRunMode        = RunMode.Sync
            });

            var sw = Stopwatch.StartNew();
            //Connection
            await Client.LoginAsync(TokenType.Bot, Credentials.Token).ConfigureAwait(false);

            await Client.StartAsync().ConfigureAwait(false);

            //await Client.DownloadAllUsersAsync().ConfigureAwait(false);
            sw.Stop();
            PrettyConsole.Log(LogSeverity.Info, "Successfully connected", $"Elapsed time: {sw.Elapsed.TotalSeconds.ToString()} seconds.");

            var Map = new DependencyMap();

            ConfigureServices(Map);
            await new MessageRecieved().InitializeAsync(Client, Map);
            new Ready(Client);
            PrettyConsole.Log(LogSeverity.Info, "Events and mapping successfully initialized", $"Client ready.");

            using (var db = new DEAContext())
            {
                await db.Database.EnsureCreatedAsync();
            }
            PrettyConsole.Log(LogSeverity.Info, "Database creation ensured", $"Ready for use.");
        }
Exemplo n.º 5
0
        public static void Log(CommandContext c)
        {
            var channel = (c.Channel as SocketGuildChannel);

            PrettyConsole.NewLine($"{DateTimeOffset.Now.ToString("hh:mm:ss")} ", ConsoleColor.Gray);

            if (channel == null)
            {
                PrettyConsole.Append($"[PM] ", ConsoleColor.Magenta);
            }
            else
            {
                PrettyConsole.Append($"[{c.Guild.Name} #{channel.Name}] ", ConsoleColor.DarkGreen);
            }

            PrettyConsole.Append($"{c.User}: ", ConsoleColor.Green);
            PrettyConsole.Append(c.Message.Content, ConsoleColor.White);
        }
Exemplo n.º 6
0
        public static void Log(IUserMessage msg)
        {
            var channel = (msg.Channel as IGuildChannel);

            PrettyConsole.NewLine($"{DateTimeOffset.Now.ToString("hh:mm:ss")} ", ConsoleColor.Gray);

            if (channel?.Guild == null)
            {
                PrettyConsole.Append($"[PM] ", ConsoleColor.Magenta);
            }
            else
            {
                PrettyConsole.Append($"[{channel.Guild.Name} #{channel.Name}] ", ConsoleColor.DarkGreen);
            }

            PrettyConsole.Append($"{msg.Author}: ", ConsoleColor.Green);
            PrettyConsole.Append(msg.Content, ConsoleColor.White);
        }
Exemplo n.º 7
0
        public async Task Start()
        {
            PrettyConsole.NewLine("===   DEA   ===");
            PrettyConsole.NewLine();

            using (var db = new DbContext())
            {
                db.Database.EnsureCreated();
            }

            _client = new DiscordSocketClient(new DiscordSocketConfig()
            {
                LogLevel            = LogSeverity.Error,
                AlwaysDownloadUsers = true,
                MessageCacheSize    = 10000
            });

            _client.Log += (l)
                           => Task.Run(()
                                       => PrettyConsole.Log(l.Severity, l.Source, l.Exception?.ToString() ?? l.Message));

            await _client.LoginAsync(TokenType.Bot, Token.TOKEN);

            await _client.StartAsync();

            var map = new DependencyMap();

            ConfigureServices(map);

            await new MessageRecieved().InitializeAsync(_client, map);

            new Ready(_client);
            new UserEvents(_client);
            new RoleEvents(_client);
            new ChannelEvents(_client);
            new RecurringFunctions(_client);

            await Task.Delay(-1);
        }