Beispiel #1
0
 public StartupService(IServiceProvider provider, DiscordSocketClient discord, CommandService commands, MayhemConfiguration config)
 {
     _provider = provider;
     _config   = config;
     _discord  = discord;
     _commands = commands;
 }
Beispiel #2
0
 public CommandHandler(IServiceProvider provider, MayhemConfiguration config)
 {
     _config   = config;
     _provider = provider;
     _client   = _provider.GetService <DiscordSocketClient>();
     _commands = _provider.GetService <CommandService>();
     _client.MessageReceived += OnMessageReceivedAsync;
 }
Beispiel #3
0
        // DiscordSocketClient and CommandService are injected automatically from the IServiceProvider
        public LoggingService(DiscordSocketClient discord, CommandService commands, MayhemConfiguration config)
        {
            _logDirectory = Path.Combine(AppContext.BaseDirectory, "logs");

            _discord  = discord;
            _commands = commands;
            _config   = config;

            _discord.Log  += OnLogAsync;
            _commands.Log += OnLogAsync;

            CreateLogFile();
        }
Beispiel #4
0
        public static SftpClient CreateSftpClient(MayhemConfiguration config)
        {
            if (!File.Exists(config.Ssh.KeyAuth))
            {
                throw new Exception("Key does not exists");
            }
            PrivateKeyFile privateKeyStream = new PrivateKeyFile(config.Ssh.KeyAuth);

            var connectionInfo = new PrivateKeyConnectionInfo(config.Ssh.IP,
                                                              config.Ssh.Username,
                                                              privateKeyStream);

            return(new SftpClient(connectionInfo));
        }
Beispiel #5
0
        public async Task StartAsync()
        {
            var _builder = new ConfigurationBuilder()
                           .SetBasePath(AppContext.BaseDirectory)
                           .AddJsonFile(path: "config.json")
                           .AddJsonFile("config.dev.json", true);

            _config = new MayhemConfiguration(_builder.Build());

            var services = new ServiceCollection()
                           .AddSingleton(new DiscordSocketClient(new DiscordSocketConfig
            {
                LogLevel         = LogSeverity.Verbose,
                MessageCacheSize = 1000
            }))
                           .AddSingleton(_config)
                           .AddSingleton(new CommandService(new CommandServiceConfig
            {
                DefaultRunMode        = RunMode.Async,
                LogLevel              = LogSeverity.Verbose,
                CaseSensitiveCommands = false,
                ThrowOnError          = false
            }))
                           .AddSingleton <LoggingService>()
                           .AddSingleton <CommandHandler>()
                           .AddSingleton <StartupService>();

            var serviceProvider = services.BuildServiceProvider();

            serviceProvider.GetRequiredService <DiscordSocketClient>().Log += Log;
            serviceProvider.GetRequiredService <CommandHandler>();
            serviceProvider.GetRequiredService <LoggingService>();

            await serviceProvider.GetRequiredService <StartupService>().StartAsync();

            await Task.Delay(-1);
        }
Beispiel #6
0
 public CustomCommands(MayhemConfiguration config)
 {
     _config = config;
 }
 public CS(MayhemConfiguration config)
 {
     _config = config;
 }
 public CounterStrikeCommands(MayhemConfiguration config)
 {
     _config = config;
 }