示例#1
0
        static async Task MainAsync(string[] args)
        {
            //magic to prevent OperationNotSupportedException
            var proxy = WebRequest.DefaultWebProxy;

            WebRequest.DefaultWebProxy = null;
            KomoLogger logger = new KomoLogger();

            try
            {
                config = new JsonParser().Config;
            }
            catch (Exception e) { logger.Fatal("Loading configuration", e); Console.ReadKey(); return; }

            ServiceContainer.Container.RegisterType <ITwitchService, TwitchService>(new InjectionConstructor(config.twitchClientID, config.twitchAccessToken, config.twitchChannelsToMonitor));
            ServiceContainer.Container.RegisterType <IWoWService, WoWService>(new InjectionConstructor(config.blizzardCharInfoEndpoint, config.blizzardOauthAccessTokenEndpoint, config.blizzardOauthCheckTokenEndpoint,
                                                                                                       config.client_id, config.client_secret));
            ServiceContainer.Container.RegisterType <ILeagueService, LeagueService>(new InjectionConstructor(config.lolApiKey));
            ServiceContainer.Container.RegisterType <ICoronaService, CoronaService>(new InjectionConstructor(config.coronaUrl));


            DiscordClient client = new DiscordClient(new DiscordConfiguration()
            {
                TokenType             = TokenType.Bot,
                Token                 = config.DiscordAPIKey,
                UseInternalLogHandler = true,
                LogLevel              = LogLevel.Debug,
            });


            commands = client.UseCommandsNext(new CommandsNextConfiguration
            {
                StringPrefix      = "!",
                EnableDms         = true,
                CaseSensitive     = false,
                EnableDefaultHelp = true,
            });
            commands.RegisterCommands <Commands>();

            logger.Debug("Connecting...");
            await client.ConnectAsync();

            logger.Debug("Connected, waiting for client initialization.");
            await Task.Delay(5000);

            logger.Debug("Starting initialization.");
            await Initialize(client, config);

            logger.Debug("Initialized");
            await Task.Delay(-1);
        }
        public static async Task ChannelDeleted(ChannelDeleteEventArgs e, DiscordClient client, JsonConfig config)
        {
            var log = await client.Guilds.FirstOrDefault().Value.GetAuditLogsAsync(1, null, AuditLogActionType.ChannelDelete);

            var mandatoryChannels = config.mandatoryVoiceChannels;

            if (log == null || log.Count < 1)
            {
                throw new ArgumentException("No entry found");
            }

            var user = log.FirstOrDefault().UserResponsible;

            logger.Debug(user.Username + " deleted the " + e.Channel.Name + " channel!");

            if (mandatoryChannels.Contains(e.Channel.Name))
            {
                await client.Guilds.FirstOrDefault().Value.CreateChannelAsync(e.Channel.Name, e.Channel.Type, e.Channel.Parent,
                                                                              e.Channel.Bitrate, e.Channel.UserLimit, e.Channel.PermissionOverwrites, "Mandatory channel recreation.");

                await client.SendMessageAsync(e.Guild.Channels.Where(x => x.Name == "general").FirstOrDefault(),
                                              "A(z) " + e.Channel.Name + " kötött csatorna, nem törölhető! " + user.Username + ", ellenőrző!");
            }
        }
示例#3
0
        public async Task Uptime(CommandContext ctx)
        {
            logger.Debug(ctx.User.Username + " called uptime!");

            await ctx.RespondAsync("Ha ennyire érdekel, már " + GetUptimeString() + "futok!");
        }