Пример #1
0
        public CommandHandler(ILogger <CommandHandler> logger, IBotCoreModule botCoreModuleInstance, IServiceProvider services, string commandPrefix)
        {
            _logger = logger;
            _botCoreModuleInstance = botCoreModuleInstance;
            _botCoreModuleInstance.DiscordClient.MessageCreated += (client, e) =>
            {
                Task.Run(async() =>
                {
                    await OnMessageCreated(e);
                });

                return(Task.CompletedTask);
            };
            _services = services;

            CommandPrefix = commandPrefix;

            // Auto register default converters
            GetType().Assembly.GetTypes().Where(t =>
                                                !t.IsInterface && typeof(IGenericConverter).IsAssignableFrom(t))
            .ToList().ForEach(t =>
                              _converters.Add(
                                  t.GetInterface($"{nameof(IConverter<int>)}`1").GenericTypeArguments[0], // nameof(IConverter<int>) will return IConverter
                                  Activator.CreateInstance(t) as IGenericConverter));

            // + 1: EnumConverter
            _logger.LogDebug($"{nameof(CommandHandler)}: Registered {_converters.Count + 1} type converters.");

            ConvertGeneric = GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(mi => mi.Name == nameof(TryConvertParameter) && mi.ContainsGenericParameters);
        }
Пример #2
0
        public StatusModule(ILogger <StatusModule> logger, IBotCoreModule botCoreModule)
        {
            _logger        = logger;
            _botCoreModule = botCoreModule;

            _botCoreModule.CommandHandler.RegisterCommands <StatusCommands>();
            _botCoreModule.DiscordClient.Ready += async(client, e) => await SetRandomStatus();

            _configFile = Path.Combine(Environment.CurrentDirectory, _statusConfigFileName);

            if (!File.Exists(_configFile))
            {
                _logger.LogInformation($"{nameof(StatusModule)}: No config file found. Creating default config at {_configFile}");
                StatusConfig = new StatusModuleConfig
                {
                    Mode = StatusMode.Automatic
                };
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                AddStatus(ActivityType.ListeningTo, "Rick Astley", false);
                AddStatus(ActivityType.Playing, "Minecraft");
            }
            else
            {
                LoadConfig();
            }
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            StatusTimer.Elapsed += async(object sender, ElapsedEventArgs e) =>
            {
                await SetRandomStatus();
            };
            StatusTimer.Start();
        }
Пример #3
0
        public AudioPlayerModule(ILogger <AudioPlayerModule> logger, IBotCoreModule botCoreModule, AudioPlayer config)
        {
            // These dlls are imported via DllImportAttribute which does not trigger BotRunner's assembly resolve functionality
            string opus = "libopus.dll", sodium = "libsodium.dll";

            CopyNativeLib(opus);
            CopyNativeLib(sodium);

            _logger        = logger;
            _botCoreModule = botCoreModule;
            _botCoreModule.CommandHandler.RegisterCommands <AudioPlayerCommands>();
            _botCoreModule.DiscordClient.VoiceStateUpdated += VoiceStateUpdated;

            _config             = config;
            _voiceNextExtension = _botCoreModule.DiscordClient.UseVoiceNext(new VoiceNextConfiguration {
                EnableIncoming = false
            });

            foreach (Track track in config.Tracks)
            {
                if (track.FileName != null && track.FileNames != null)
                {
                    _logger.LogWarning($"Track \"{track.Name}\" has a file name and a list of file names, if the file name is not also included in the list it will not be used as a trigger!");
                }
            }
        }
Пример #4
0
        public ModModule(ILogger <ModModule> logger, IBotCoreModule botCoreModule)
        {
            _logger        = logger;
            _botCoreModule = botCoreModule;

            _botCoreModule.CommandHandler.RegisterCommands <ModCommands>();
            _botCoreModule.DiscordClient.MessageUpdated += OnMessageUpdated;
        }
Пример #5
0
        public CommandContext(MessageCreateEventArgs messageCreateEventArgs, IBotCoreModule botCoreModule,
                              DiscordMember discordMember, Permissions channelPermissions, string aliasUsed, string argumentString)
        {
            _event = messageCreateEventArgs;

            BotCoreModule = botCoreModule;
            Member        = discordMember;

            ChannelPermissions = channelPermissions;

            AliasUsed      = aliasUsed;
            ArgumentString = argumentString;
        }
Пример #6
0
        public SteamHelperModule(ILoggerFactory loggerFactory, IBotCoreModule botCoreModule, ISteamWebApiHelper steamWebApiHelper)
        {
            _logger        = loggerFactory.CreateLogger <SteamHelperModule>();
            _botCoreModule = botCoreModule;

            _botCoreModule.CommandHandler.RegisterCommands <SteamCommands>();
            _botCoreModule.DiscordClient.MessageCreated += (client, e) =>
            {
                Task.Run(async() =>
                {
                    await OnMessageCreated(client, e);
                });

                return(Task.CompletedTask);
            };

            _steamWebApiHelper = steamWebApiHelper;
        }
Пример #7
0
        public async Task Tracks(CommandContext ctx, int page = 1, [FromServices] AudioPlayerModule module = null, [FromServices] IBotCoreModule botCore = null)
        {
            if (page <= 0)
            {
                await ctx.Message.RespondAsync("Please select a page number greater than 0.");

                return;
            }

            DiscordEmbedBuilder builder = new DiscordEmbedBuilder()
                                          .WithTitle("Tracks")
                                          .WithCustomFooterWithColour(ctx);

            IEnumerable <Track> tracks = module.GetTracksForGuild(ctx.Guild.Id);

            if (tracks.Count() > module.TrackPageSize)
            {
                int pageCount = (tracks.Count() / module.TrackPageSize) + ((tracks.Count() % module.TrackPageSize) == 0 ? 0 : 1);
                builder.WithDescription($"Showing page {page} of {pageCount}. Use `{botCore.CommandHandler.CommandPrefix}tracks <pageNumber>` to view more.");

                if (page == 1)
                {
                    tracks = tracks.Take(module.TrackPageSize);
                }
                else
                {
                    tracks = tracks.Skip((page - 1) * module.TrackPageSize).Take(module.TrackPageSize);
                }
            }

            if (!tracks.Any())
            {
                await ctx.Message.RespondAsync("No tracks on that page.");

                return;
            }

            foreach (Track track in tracks)
            {
                builder.AddField(track.Name, track.Description ?? "No description provided.");
            }

            await ctx.Message.RespondAsync(embed : builder);

            await ctx.Message.DeleteAsync();
        }
Пример #8
0
 public Worker(ILogger <Worker> logger, IServiceProvider serviceProvider, IBotCoreModule botCoreModule) =>
 (_logger, _serviceProvider, _botCoreModule) = (logger, serviceProvider, botCoreModule);