コード例 #1
0
        public App(IConfiguration configuration, DiscordSocketClient client,
                   ICommandHandlingService commandHandler, IEventService eventService)
        {
            _configuration = configuration;
            _client        = client;

            _commandHandler = commandHandler;
            _eventService   = eventService;
        }
コード例 #2
0
    public DiscordBot(IServiceProvider serviceProvider, IOptions <DiscordBotConfiguration> configuration,
                      CommandService commandService, DiscordSocketClient bot, ILogger <DiscordBot> logger,
                      ICommandHandlingService commandHandlingService)
    {
        _configuration = configuration.Value;
        _bot           = bot;
        _logger        = logger;

        _bot.Log             += Log;
        _bot.MessageReceived += message =>
                                commandHandlingService.HandleMessageReceivedAsync(message, _bot, commandService);

        commandService.CommandExecuted += commandHandlingService.HandleCommandExecutedAsync;
        commandService.AddModuleAsync <ChannelsManagementModule>(serviceProvider).ConfigureAwait(false).GetAwaiter()
        .GetResult();
    }
コード例 #3
0
 public ApiController(ICommandHandlingService command, WebCommunicationService communication)
 {
     _command       = command;
     _communication = communication;
 }
コード例 #4
0
        public async Task MainAsync(IServiceProvider services)
        {
            Logger = services.GetRequiredService <LoggingService>();
            await Logger.InitializeAsync();

            var config = services.GetRequiredService <IBotConfigurationService>();

            if (config.Initialize())
            {
                var client = services.GetRequiredService <IDiscordClient>() as DiscordSocketClient;

                client.Log        += LogMessageAsync;
                client.UserJoined += async(SocketGuildUser user) =>
                {
                    int welcomeMessageIndex = m_random.Next(0, config.Configuration.WelcomeMessages.Length);
                    await user.Guild.SystemChannel.SendMessageAsync(string.Format(config.Configuration.WelcomeMessages[welcomeMessageIndex], user.Mention, user.Guild.Name));
                };
                client.Ready += async() =>
                {
                    await client.SetGameAsync(config.Configuration.StatusMessage.Replace(":serverCount:", client.Guilds.Count.ToString()).Replace(":prefix:", config.Configuration.Prefix), type : config.Configuration.Activity);

                    await client.SetStatusAsync(config.Configuration.OnlineStatus);
                };

                services.GetRequiredService <CommandService>().Log += LogMessageAsync;

                if (config.Configuration.Token == "YOUR TOKEN")
                {
                    throw new ConfigurationException("Default token detected, please put your token in the config file");
                }
                await client.LoginAsync(TokenType.Bot, config.Configuration.Token, true);

                await client.StartAsync();

                ICommandHandlingService commandService = services.GetRequiredService <ICommandHandlingService>();

                Logger.LogInfo("Initializing services!");
                await services.GetRequiredService <JsonDatabaseService>().InitializeAsync();

                await commandService.InitializeAsync();

                await services.GetRequiredService <WordBlacklistService>().InitializeAsync();

                await services.GetRequiredService <PaginatedMessageService>().InitializeAsync();

                await services.GetRequiredService <InviteLinkDetectorService>().InitializeAsync();

                await services.GetRequiredService <MessageRewardService>().InitializeAsync();

                services.GetRequiredService <SchedulerService>().Initialize();

                client.MessageReceived += msg => commandService.HandleCommandAsync((msg as IUserMessage) !, true);

                if (Environment.UserInteractive && !Console.IsInputRedirected)
                {
                    Logger.LogInfo("Initializing command line");
                    await services.GetRequiredService <CommandLineHandlingService>().InitializeAsync();
                }
                else
                {
                    Logger.LogInfo("Not initializing command line, non-interactive environment");
                    try
                    {
                        await Task.Delay(-1, tokenSource.Token);
                    }
                    catch (TaskCanceledException)
                    {
                        // do nothing
                    }
                }
            }
        }