Beispiel #1
0
 public ChatTrackerModule(IDiscordSettings discordSettings, ILogger <IModule> logger, IConfiguration config,
                          IServiceScopeFactory scopeFactory, IModuleSettingsService <ChatTrackerSettings> settingsService) : base(
         discordSettings, logger, config)
 {
     _scopeFactory    = scopeFactory;
     _settingsService = settingsService;
 }
Beispiel #2
0
 public DiscordService(IDiscordSettings settings)
 {
     _id          = settings.ID;
     _secret      = settings.Secret;
     _redirectURL = settings.RedirectURL;
     _token       = settings.Token;
 }
 /// <summary>
 ///     Assign a user the streaming role.
 /// </summary>
 /// <param name="discordSettings">Settings used to connect to Discord.</param>
 /// <param name="logger">Logger.</param>
 public StreamerRoleCommand(DiscordSocketClient discordSocketClient, IDiscordSettings discordSettings,
                            ILogger <StreamerRoleCommand> logger)
 {
     this.discordSocketClient = discordSocketClient;
     this.discordSettings     = discordSettings;
     this.logger = logger;
 }
 public CleanChatModule(IDiscordSettings discordSettings, ILogger <IModule> logger, IConfiguration config,
                        IModuleSettingsService <CleanChatSettings> settingsService, IJobService jobService,
                        IServiceScopeFactory scopeFactory) : base(discordSettings, logger, config)
 {
     _settingsService = settingsService;
     _jobService      = jobService;
     _scopeFactory    = scopeFactory;
 }
Beispiel #5
0
        public DiscordService(HttpClient client, IDiscordSettings settings)
        {
            _client = client;

            ID          = settings.ID;
            Secret      = settings.Secret;
            RedirectURL = settings.RedirectURL;
        }
 /// <summary>
 ///     Announce the user to a specified channel when the user starts streaming and assign specified streaming role to the
 ///     user.
 /// </summary>
 /// <param name="discordSettings">Settings used to connect to Discord.</param>
 /// <param name="logger">Logger.</param>
 /// <param name="config">Application configuration.</param>
 /// <param name="settingsService">Settings service.</param>
 /// <param name="scopeFactory">Scope factory.</param>
 public StreamerModule(IDiscordSettings discordSettings, ILogger <StreamerModule> logger,
                       IConfiguration config, IModuleSettingsService <StreamerSettings> settingsService,
                       IServiceScopeFactory scopeFactory) : base(
         discordSettings, logger, config)
 {
     _settingsService = settingsService;
     _scopeFactory    = scopeFactory;
 }
Beispiel #7
0
        /// <summary>
        ///     Discord bot.
        /// </summary>
        /// <param name="settings">Settings used to connect to Discord.</param>
        /// <param name="logger">Application logger.</param>
        public Bot(DiscordSocketClient discordSocketClient, IDiscordSettings settings, ILogger <Bot> logger)
        {
            this.discordSocketClient = discordSocketClient;
            Logger = logger;

            // TODO: Convert logging to command
            discordSocketClient.Log += Log;
            Connector = new BotConnector(settings, discordSocketClient);
        }
Beispiel #8
0
        /// <summary>
        /// Discord bot.
        /// </summary>
        /// <param name="modules">List of modules for the bot.</param>
        /// <param name="settings">Settings used to connect to Discord.</param>
        /// <param name="logger">Application logger.</param>
        public Bot(DiscordSocketClient discordSocketClient, IList <IModule> modules, IDiscordSettings settings, ILogger <Bot> logger)
        {
            this.discordSocketClient = discordSocketClient;
            Modules = modules;
            Logger  = logger;

            // TODO: Convert logging to module
            discordSocketClient.Log += Log;
            Connector = new BotConnector(settings, discordSocketClient);
        }
Beispiel #9
0
        public DadModule(IDiscordSettings discordSettings,
                         ILogger <IModule> logger,
                         IConfiguration config,
                         IModuleSettingsService <DadModuleSettings> moduleSettings)
            : base(discordSettings, logger, config)
        {
            _moduleSettings = moduleSettings;

            _dadName      = config[DadNameKey];
            _matchPattern = config[MatchPatternKey];
            _pattern      = new Regex(config[MatchPatternKey]);
        }
Beispiel #10
0
        /// <summary>
        ///     Discord bot.
        /// </summary>
        /// <param name="modules">List of modules for the bot.</param>
        /// <param name="settings">Settings used to connect to Discord.</param>
        /// <param name="logger">Application logger.</param>
        public Bot(IList <IModule> modules, IDiscordSettings settings, ILogger <Bot> logger, DiscordSocketClient client)
        {
            Modules = modules;
            Logger  = logger;
            Client  = client;

            Client.Log += Log;

            // Log when the bot is disconnected.
            Client.Disconnected += exception =>
            {
                Logger.LogCritical("Bot has been disconnected!");

                return(Task.CompletedTask);
            };

            // Set bot game.
            Client.Ready += () =>
            {
                Task.Run(async() =>
                {
                    for (;;)
                    {
                        var memberCount = Client.Guilds.Sum(guild => guild.MemberCount);

                        await Client.SetGameAsync($"volvox.tech | {Client.Guilds.Count} servers > {memberCount} members");
                        await Task.Delay(TimeSpan.FromMinutes(15));
                    }
                });

                return(Task.CompletedTask);
            };

            // Announce to Volvox when the bot joins a guild.
            Client.JoinedGuild += async guild =>
            {
                await Client.GetGuild(VolvoxGuildId).GetTextChannel(VolvoxGuildLogsChannelId)
                .SendMessageAsync($"Joined Guild: {guild.Name} [{guild.MemberCount} Members]");
            };

            // Announce to Volvox when the bot leaves a guild.
            Client.LeftGuild += async guild =>
            {
                await Client.GetGuild(VolvoxGuildId).GetTextChannel(VolvoxGuildLogsChannelId)
                .SendMessageAsync($"Left Guild: {guild.Name} [{guild.MemberCount} Members]");
            };

            // Add reliability service.
            _ = new ReliabilityService(Client, logger);

            Connector = new BotConnector(settings, Client);
        }
Beispiel #11
0
 /// <summary>
 /// .ctor
 /// </summary>
 /// <param name="discordSettings"></param>
 /// <param name="logger"></param>
 /// <param name="config"></param>
 /// <param name="jobService"></param>
 /// <param name="moduleSettings"></param>
 /// <param name="entityChangedDispatcher"></param>
 /// <param name="scopeFactory"></param>
 public RemembotModule(IDiscordSettings discordSettings,
                       ILogger <IModule> logger,
                       IConfiguration config,
                       IJobService jobService,
                       IModuleSettingsService <RemembotSettings> moduleSettings,
                       EntityChangedDispatcher <RecurringReminderMessage> entityChangedDispatcher,
                       IServiceScopeFactory scopeFactory)
     : base(discordSettings, logger, config)
 {
     _jobService              = jobService;
     _moduleSettings          = moduleSettings;
     _entityChangedDispatcher = entityChangedDispatcher;
     _scopeFactory            = scopeFactory;
 }
Beispiel #12
0
        /// <summary>
        /// Discord bot.
        /// </summary>
        /// <param name="modules">List of modules for the bot.</param>
        /// <param name="settings">Settings used to connect to Discord.</param>
        /// <param name="logger">Application logger.</param>
        public Bot(IList <IModule> modules, IDiscordSettings settings, ILogger <Bot> logger)
        {
            Modules = modules;
            Logger  = logger;

            // TODO: Convert logging to module
            Client = new DiscordSocketClient(new DiscordSocketConfig()
            {
                LogLevel = LogSeverity.Verbose
            });

            Client.Log += Log;

            Connector = new BotConnector(settings, Client);
        }
        public ModerationModule(IDiscordSettings discordSettings, ILogger <ModerationModule> logger,
                                IConfiguration config, IServiceScopeFactory scopeFactory,
                                IJobService jobService, IEnumerable <IFilterService> filters, IBypassCheck bypassCheck,
                                IModerationModuleUtils moderationModuleUtils,
                                IViolationService violationService
                                ) : base(
                discordSettings, logger, config)
        {
            _scopeFactory = scopeFactory;

            _jobService = jobService;

            _filters = filters;

            _bypassCheck = bypassCheck;

            _moderationModuleUtils = moderationModuleUtils;

            _violationService = violationService;
        }
Beispiel #14
0
        /// <summary>
        /// Discord bot.
        /// </summary>
        /// <param name="modules">List of modules for the bot.</param>
        /// <param name="settings">Settings used to connect to Discord.</param>
        /// <param name="logger">Application logger.</param>
        public Bot(IList <IModule> modules, IDiscordSettings settings, ILogger <Bot> logger)
        {
            Modules = modules;
            Logger  = logger;

            // TODO: Convert logging to module
            Client = new DiscordSocketClient(new DiscordSocketConfig()
            {
                LogLevel = LogSeverity.Verbose
            });

            Client.Log += Log;

            // Log when the bot is disconnected.
            Client.Disconnected += exception =>
            {
                Logger.LogCritical("Bot has been disconnected!");

                return(Task.CompletedTask);
            };

            // Set bot game.
            Client.Ready += () =>
            {
                Task.Run(async() =>
                {
                    for (;;)
                    {
                        await Client.SetGameAsync($"volvox.tech | with {Client.Guilds.Count} servers");
                        await Task.Delay(TimeSpan.FromMinutes(15));
                    }
                });

                return(Task.CompletedTask);
            };

            // Add reliability service.
            _ = new ReliabilityService(Client, logger);

            Connector = new BotConnector(settings, Client);
        }
Beispiel #15
0
        public IActionResult Index(ulong guildId, [FromServices] IBot bot,
                                   [FromServices] IDiscordSettings discordSettings, [FromServices] IList <IModule> modules)
        {
            if (bot.IsBotInGuild(guildId))
            {
                var viewModel = new SettingsIndexViewModel
                {
                    GuildId   = guildId,
                    GuildName = bot.GetGuilds().FirstOrDefault(g => g.Id == guildId)?.Name,
                    Modules   = modules.Where(mod => mod.Configurable).ToList()
                };

                return(View(viewModel));
            }

            // Bot is not in guild so redirect to the add bot URL.
            var redirectUrl = Uri.EscapeDataString($"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}");

            return(Redirect(
                       $"https://discordapp.com/api/oauth2/authorize?client_id={discordSettings.ClientId}&permissions=8&redirect_uri={redirectUrl}&scope=bot&guild_id={guildId}"));
        }
Beispiel #16
0
        /// <summary>
        ///     Unit of the bot.
        /// </summary>
        /// <param name="discordSettings">Settings used to connect to Discord.</param>
        /// <param name="logger">Logger.</param>
        /// <param name="config">Application configuration.</param>
        protected Module(IDiscordSettings discordSettings, ILogger <IModule> logger, IConfiguration config)
        {
            DiscordSettings = discordSettings;
            Logger          = logger;

            var moduleName = GetType().Name;

            // Check if the module exists in the metadata.
            if (config.GetSection($"ModuleMetadata:{moduleName}").Exists())
            {
                Name         = config[$"ModuleMetadata:{moduleName}:Name"];
                Version      = config[$"ModuleMetadata:{moduleName}:Version"];
                Description  = config[$"ModuleMetadata:{moduleName}:Description"];
                Configurable = bool.Parse(config[$"ModuleMetadata:{moduleName}:Configurable"]);
                ReleaseState = Enum.Parse <ReleaseState>(config[$"ModuleMetadata:{moduleName}:ReleaseState"]);
            }

            else
            {
                Logger.LogError($"Module cannot be found in the metadata! Name: {moduleName}");
            }
        }
Beispiel #17
0
 /// <summary>
 /// Unit of the bot.
 /// </summary>
 /// <param name="discordSettings">Settings used to connect to Discord.</param>
 protected Module(IDiscordSettings discordSettings, ILogger <IModule> logger)
 {
     DiscordSettings = discordSettings;
     Logger          = logger;
 }
 /// <summary>
 ///     Assign a user the streaming role.
 /// </summary>
 /// <param name="discordSettings">Settings used to connect to Discord.</param>
 /// <param name="logger">Logger.</param>
 /// <param name="config">Application configuration.</param>
 /// <param name="settingsService">Settings service.</param>
 public StreamerRoleModule(IDiscordSettings discordSettings, ILogger <StreamerRoleModule> logger,
                           IConfiguration config, IModuleSettingsService <StreamerRoleSettings> settingsService) : base(discordSettings,
                                                                                                                        logger, config)
 {
     _settingsService = settingsService;
 }
 /// <summary>
 ///     Manager for Discord message commands.
 /// </summary>
 /// <param name="logger">Logger.</param>
 /// <param name="modules">List of Command modules to be used by the manager.</param>
 /// <param name="settings">Discord settings.</param>
 /// <param name="config">Configuration.</param>
 public CommandManager(ILogger <IModule> logger, IList <ICommand> modules, IDiscordSettings settings,
                       IConfiguration config) : base(settings, logger, config)
 {
     Modules = modules;
 }
 /// <summary>
 /// Announce the user to a specified channel when streaming.
 /// </summary>
 /// <param name="discordSettings">Settings used to connect to Discord.</param>
 /// <param name="logger">Logger.</param>
 /// <param name="settingsService">Settings serivce.</param>
 public StreamAnnouncerModule(IDiscordSettings discordSettings, ILogger <StreamAnnouncerModule> logger, IModuleSettingsService <StreamAnnouncerSettings> settingsService) : base(discordSettings, logger)
 {
     _settingsService = settingsService;
 }
 /// <summary>
 ///     Discord bot connector.
 /// </summary>
 /// <param name="discordSettings">Settings used to connect to Discord.</param>
 /// <param name="client">Client used to connect to Discord.</param>
 public BotConnector(IDiscordSettings discordSettings, DiscordSocketClient client)
 {
     _discordSettings = discordSettings;
     _client          = client;
 }
Beispiel #22
0
 /// <summary>
 /// Assign a user the streaming role.
 /// </summary>
 /// <param name="discordSettings">Settings used to connect to Discord.</param>
 /// <param name="logger">Logger.</param>
 public StreamerRoleModule(IDiscordSettings discordSettings, ILogger <StreamerRoleModule> logger) : base(discordSettings, logger)
 {
 }
Beispiel #23
0
        /// <summary>
        ///     Discord bot.
        /// </summary>
        /// <param name="modules">List of modules for the bot.</param>
        /// <param name="settings">Settings used to connect to Discord.</param>
        /// <param name="logger">Application logger.</param>
        public Bot(IList <IModule> modules, IDiscordSettings settings, ILogger <Bot> logger, DiscordSocketClient client)
        {
            Modules = modules;
            Logger  = logger;
            Client  = client;

            Client.Log += Log;

            // Log when the bot is disconnected.
            Client.Disconnected += exception =>
            {
                Logger.LogCritical("Bot has been disconnected!");

                return(Task.CompletedTask);
            };

            // Set bot game.
            Client.Ready += () =>
            {
                Task.Run(async() =>
                {
                    for (;;)
                    {
                        var memberCount = Client.Guilds.Sum(guild => guild.MemberCount);
                        var version     = System.Reflection.Assembly.GetEntryAssembly().GetName().Version;

                        await Client.SetGameAsync(
                            $"volvox.tech | {Client.Guilds.Count} servers | {memberCount} members | v{version.Major}.{version.Minor}.{version.Build}");
                        await Task.Delay(TimeSpan.FromMinutes(15));
                    }
                });

                return(Task.CompletedTask);
            };

            // Announce to Volvox when the bot joins a guild.
            Client.JoinedGuild += async guild =>
            {
                var channel = Client.GetGuild(VolvoxGuildId)?.GetTextChannel(VolvoxGuildLogsChannelId);

                if (channel != null)
                {
                    var builder = new EmbedBuilder();

                    builder.Title = "New Guild";
                    builder.Color = EmbedColors.GuildJoinColor;

                    await channel.SendMessageAsync("", false, CreateEmbed(builder, guild));
                }
            };

            // Announce to Volvox when the bot leaves a guild.
            Client.LeftGuild += async guild =>
            {
                var channel = Client.GetGuild(VolvoxGuildId)?.GetTextChannel(VolvoxGuildLogsChannelId);

                if (channel != null)
                {
                    var builder = new EmbedBuilder();

                    builder.Title = "Left Guild";
                    builder.Color = EmbedColors.ErrorColor;

                    await channel.SendMessageAsync("", false, CreateEmbed(builder, guild));
                }
            };

            // Add reliability service.
            _ = new ReliabilityService(Client, logger);

            Connector = new BotConnector(settings, Client);
        }