示例#1
0
        public async Task Start()
        {
            timeSinceStartup = DateTime.Now;

            Log.OnLog += (msg, e) => Console.WriteLine(msg);

            LogColor color = new LogColor();

            color.Foreground = ConsoleColor.Red;
            Log.Theme.SetColor(LogLevel.Error, color);

            LoadLocales();

            await LoadDiscord();

            for (int i = 0; i < Global.Config.MessageWorkerCount; i++)
            {
                MessageBucket.AddWorker();
            }

            using (var c = new MikiContext())
            {
                List <User> bannedUsers = await c.Users.Where(x => x.Banned).ToListAsync();

                foreach (var u in bannedUsers)
                {
                    bot.GetAttachedObject <EventSystem>().MessageFilter
                    .Get <UserFilter>().Users.Add(u.Id.FromDbLong());
                }
            }

            await bot.ConnectAsync(Global.Config.Token);
        }
示例#2
0
        private static async Task Main()
        {
            Program p = new Program();

            var appBuilder = new MikiAppBuilder();

            await p.LoadServicesAsync(appBuilder);

            MikiApp app = appBuilder.Build();

            await p.LoadDiscord(app);

            p.LoadLocales();

            for (int i = 0; i < Global.Config.MessageWorkerCount; i++)
            {
                MessageBucket.AddWorker();
            }

            using (var c = new MikiContext())
            {
                List <User> bannedUsers = await c.Users.Where(x => x.Banned).ToListAsync();

                foreach (var u in bannedUsers)
                {
                    app.GetService <EventSystem>().MessageFilter
                    .Get <UserFilter>().Users.Add(u.Id.FromDbLong());
                }
            }

            await Task.Delay(-1);
        }
示例#3
0
        static async Task Main()
        {
            Program p = new Program();

            timeSinceStartup = DateTime.Now;

            p.InitLogging();

            p.LoadLocales();

            await p.LoadDiscord();

            if (!string.IsNullOrWhiteSpace(Global.Config.MikiApiKey))
            {
                Global.MikiApi = new MikiApi(Global.Config.MikiApiBaseUrl, Global.Config.MikiApiKey);
            }

            for (int i = 0; i < Global.Config.MessageWorkerCount; i++)
            {
                MessageBucket.AddWorker();
            }

            using (var c = new MikiContext())
            {
                List <User> bannedUsers = await c.Users.Where(x => x.Banned).ToListAsync();

                foreach (var u in bannedUsers)
                {
                    Global.Client.GetAttachedObject <EventSystem>().MessageFilter
                    .Get <UserFilter>().Users.Add(u.Id.FromDbLong());
                }
            }
            await Task.Delay(-1);
        }
示例#4
0
        private static async Task Main()
        {
            Program p = new Program();

            Global.RedisClient = new StackExchangeCacheClient(
                new ProtobufSerializer(),
                await ConnectionMultiplexer.ConnectAsync(Global.Config.RedisConnectionString)
                );

            await p.LoadDiscord();

            p.LoadLocales();

            Global.Backgrounds = new BackgroundStore();

            for (int i = 0; i < Global.Config.MessageWorkerCount; i++)
            {
                MessageBucket.AddWorker();
            }

            using (var c = new MikiContext())
            {
                List <User> bannedUsers = await c.Users.Where(x => x.Banned).ToListAsync();

                foreach (var u in bannedUsers)
                {
                    Global.Client.GetAttachedObject <EventSystem>().MessageFilter
                    .Get <UserFilter>().Users.Add(u.Id.FromDbLong());
                }
            }

            await Task.Delay(-1);
        }
示例#5
0
 public static void QueueMessageAsync(this IDiscordChannel channel, string message)
 => MessageBucket.Add(new MessageBucketArgs()
 {
     properties = new MessageArgs()
     {
         content = message
     },
     channel = channel
 });
示例#6
0
 public static void QueueToChannel(this DiscordEmbed embed, IDiscordChannel channel)
 {
     MessageBucket.Add(new MessageBucketArgs()
     {
         properties = new MessageArgs()
         {
             embed = embed
         },
         channel = channel
     });
 }
示例#7
0
        private static async Task Main(string[] args)
        {
            Program p = new Program();

            if (args.Length > 0)
            {
                if (args.Any(x => x.ToLowerInvariant() == "--migrate" && x.ToLowerInvariant() == "-m"))
                {
                    await new MikiDbContextFactory().CreateDbContext(new string[] { }).Database.MigrateAsync();
                    return;
                }
            }

            var appBuilder = new MikiAppBuilder();

            await p.LoadServicesAsync(appBuilder);

            MikiApp app = appBuilder.Build();

            await p.LoadDiscord(app);

            p.LoadLocales();

            for (int i = 0; i < Global.Config.MessageWorkerCount; i++)
            {
                MessageBucket.AddWorker();
            }

            using (var scope = app.Services.CreateScope())
            {
                var context = scope.ServiceProvider
                              .GetService <MikiDbContext>();

                List <IsBanned> bannedUsers = await context.IsBanned
                                              .Where(x => x.ExpirationDate > DateTime.UtcNow)
                                              .ToListAsync();

                foreach (var u in bannedUsers)
                {
                    app.GetService <EventSystem>().MessageFilter
                    .Get <UserFilter>().Users.Add(u.UserId.FromDbLong());
                }
            }

            await Task.Delay(-1);
        }
示例#8
0
文件: Program.cs 项目: hlinkad/Miki
        public async Task Start()
        {
            timeSinceStartup = DateTime.Now;

            Log.OnLog += (msg, e) =>
            {
                if (e >= LogLevel.Information)
                {
                    Console.WriteLine(msg);
                }
            };

            Log.Theme.SetColor(LogLevel.Error, new LogColor {
                Foreground = ConsoleColor.Red
            });
            Log.Theme.SetColor(LogLevel.Warning, new LogColor {
                Foreground = ConsoleColor.Yellow
            });

            LoadLocales();

            await LoadDiscord();

            for (int i = 0; i < Global.Config.MessageWorkerCount; i++)
            {
                MessageBucket.AddWorker();
            }

            using (var c = new MikiContext())
            {
                List <User> bannedUsers = await c.Users.Where(x => x.Banned).ToListAsync();

                foreach (var u in bannedUsers)
                {
                    Global.Client.GetAttachedObject <EventSystem>().MessageFilter
                    .Get <UserFilter>().Users.Add(u.Id.FromDbLong());
                }
            }
            await Task.Delay(-1);
        }