Beispiel #1
0
        public Bot()
        {
            Client = new DiscordSocketClient(new DiscordSocketConfig
            {
                LogLevel = LogSeverity.Debug
            });

            Commands = new CommandService(new CommandServiceConfig
            {
                LogLevel = LogSeverity.Debug,
                CaseSensitiveCommands = true,
                DefaultRunMode        = RunMode.Async,
                IgnoreExtraArgs       = true
            });

            Interactive = new InteractiveService(Client, new InteractiveServiceConfig
            {
                DefaultTimeout = TimeSpan.FromMinutes(2)
            });

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Information()
                         .MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Debug)
                         .MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Information)
                         .WriteTo.Console(
                outputTemplate: "{Timestamp:HH:mm:ss} - [{Level:u4}] => {Message:lj}{NewLine}{Exception}"
                )
                         .CreateLogger();

            Services = BuildServiceProvder();
        }
Beispiel #2
0
 public Trivia(GuildRepository guildRepo, UserRepository userRepo, InteractiveService interactiveService, GameService gameService)
 {
     _guildRepo          = guildRepo;
     _userRepo           = userRepo;
     _interactiveService = interactiveService;
     _gameService        = gameService;
 }
Beispiel #3
0
 public HelpService(SkillsService skillsService,
                    SpecialService specialService,
                    InteractiveService interactiveService)
 {
     _skillsService      = skillsService;
     _interactiveService = interactiveService;
 }
Beispiel #4
0
 public AudioModule(
     LavaNode node,
     InteractiveService interactiveService)
 {
     _node = node;
     _interactiveService = interactiveService;
 }
Beispiel #5
0
 public Items(UserRepository userRepo, InteractiveService interactiveService, GameService gameService, CooldownService cooldownService)
 {
     _userRepo           = userRepo;
     _interactiveService = interactiveService;
     _gameService        = gameService;
     _cooldownService    = cooldownService;
 }
Beispiel #6
0
 public HelpCommand(CommandService commands, MiscService misc, IServiceProvider services, InteractiveService inter)
 {
     _commands = commands;
     _misc     = misc;
     _services = services;
     _inter    = inter;
 }
Beispiel #7
0
 public CommandsCommand(CommandService commands, MiscService misc, RandomService rand, InteractiveService inter)
 {
     _commands = commands;
     _misc     = misc;
     _rand     = rand;
     _inter    = inter;
 }
Beispiel #8
0
 public Gangs(GangRepository gangRepo, UserRepository userRepo, InteractiveService interactiveService, CooldownService CooldownService)
 {
     _gangRepo           = gangRepo;
     _userRepo           = userRepo;
     _interactiveService = interactiveService;
     _cooldownService    = CooldownService;
 }
Beispiel #9
0
        public async Task Reset_Points()
        {
            _interactiveService = new InteractiveService(_client.GetShardFor(Context.Guild));
            var violators = (await _unit.Violators.GetAllAsync(Context.Guild)).ToList();

            await ReplyAsync(
                $"Are you sure you want to reset all points for all Users in {Context.Guild} ? *({violators.Count} total)*" +
                "\n**Yes** - confirm" +
                "\n**No** - cancel" +
                "\n**30 sec timeout**");

            var response = await _interactiveService.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(30),
                                                                    new MessageContainsResponsePrecondition("yes"));

            if (response.Content.ToLower() == "yes")
            {
                var changes = ClearPoints(Context.Guild);
                await ReplyAsync($"{changes} {(changes > 1 ? "entries" : "entry")} deleted!");

                var logger = LogManager.GetLogger("Violations");
                logger.Info($"Removed all [{changes}] Violator entries for {Context.Guild}");
                try
                {
                    await response.DeleteAsync();
                }
                catch (Exception e)
                {
                    LogManager.GetLogger("GuildModule").Warn(e, $"Failed to delete message {response.Id} by {response.Author} in {Context.Guild}/{Context.Channel}");
                }
            }
            else
            {
                await ReplyAsync("*Canceled*");
            }
        }
 public KickUserRcon(SocketCommandContext context, InteractiveService interactive, DataService data, LogHandler log)
 {
     _context     = context;
     _interactive = interactive;
     _data        = data;
     _log         = log;
 }
Beispiel #11
0
        public static async Task <IUserMessage> SendInteractiveMessageAsync
        (
            this InteractiveService @this,
            [NotNull] SocketCommandContext context,
            [NotNull] IInteractiveMessage interactiveMessage,
            [CanBeNull] ISocketMessageChannel channel = null
        )
        {
            channel = channel ?? context.Channel;

            var message = await interactiveMessage.DisplayAsync(channel);

            if (interactiveMessage.ReactionCallback is null)
            {
                return(message);
            }

            @this.AddReactionCallback(message, interactiveMessage.ReactionCallback);

            if (interactiveMessage.Timeout.HasValue)
            {
                // ReSharper disable once AssignmentIsFullyDiscarded
                _ = Task.Delay(interactiveMessage.Timeout.Value).ContinueWith(c =>
                {
                    @this.RemoveReactionCallback(interactiveMessage.Message);
                    interactiveMessage.Message.DeleteAsync();
                });
            }

            return(message);
        }
Beispiel #12
0
        public static async Task <IUserMessage> SendPrivateInteractiveMessageAsync
        (
            this InteractiveService @this,
            [NotNull] SocketCommandContext context,
            [NotNull] UserFeedbackService feedback,
            [NotNull] IInteractiveMessage interactiveMessage
        )
        {
            if (!(await context.User.GetOrCreateDMChannelAsync() is ISocketMessageChannel userChannel))
            {
                throw new InvalidOperationException("Could not create DM channel for target user.");
            }

            try
            {
                await feedback.SendConfirmationAsync(context, "Loading...");
            }
            catch (HttpException hex) when(hex.WasCausedByDMsNotAccepted())
            {
                await feedback.SendWarningAsync(context, "You don't accept DMs from non-friends on this server, so I'm unable to do that.");

                throw new InvalidOperationException("User does not accept DMs from non-friends.");
            }
            finally
            {
                await((IDMChannel)userChannel).CloseAsync();
            }

            if (!context.IsPrivate)
            {
                await feedback.SendConfirmationAsync(context, "Please check your private messages.");
            }

            return(await SendInteractiveMessageAsync(@this, context, interactiveMessage, userChannel));
        }
Beispiel #13
0
 public SetCommand(MiscService misc, DbService db, InteractiveService inter, RandomService rand)
 {
     _misc  = misc;
     _db    = db;
     _inter = inter;
     _rand  = rand;
 }
Beispiel #14
0
 public UtilityModule(DatabaseService databaseService, ResponseService responseService, HelperService helperService, InteractiveService interactiveService)
 {
     _databaseService    = databaseService;
     _responseService    = responseService;
     _helperService      = helperService;
     _interactiveService = interactiveService;
 }
        public override void Start(ImageViewer imageViewer)
        {
            base.Start(imageViewer);
            InteractiveService service = base.InteractiveService;

            service.Tap += new EventHandler <InteractiveEventArgs>(service_Tap);
        }
Beispiel #16
0
 public KickUserRcon(SocketCommandContext context, InteractiveService interactive, RconService rconService,
                     LogHandler log)
 {
     _context     = context;
     _interactive = interactive;
     _rconService = rconService;
     _log         = log;
 }
        public ChannelFilters(DiscordSocketClient discord, TownDatabase database, InteractiveService interactive)
        {
            this.database    = database;
            this.discord     = discord;
            this.interactive = interactive;

            discord.MessageReceived += Handle;
        }
Beispiel #18
0
 public VerificationModule(DiscordSocketClient client, CommandService commands, DataService data, VerificationService verificationService, InteractiveService interactive)
 {
     _client              = client;
     _commands            = commands;
     _dataService         = data;
     _verificationService = verificationService;
     _interactive         = interactive;
 }
Beispiel #19
0
 /// <summary>
 /// Interaction handler constructor.
 /// </summary>
 /// <param name="client">The current <see cref="DiscordSocketClient"/>.</param>
 /// <param name="interactionCommands">The Discord interaction command service.</param>
 /// <param name="interactiveService">The interactive service to handle pagination and selections.</param>
 /// <param name="services">The service provider.</param>
 /// <param name="logger">The log4net <see cref="ILog"/> instance.</param>
 public InteractionHandler(DiscordSocketClient client, InteractionService interactionCommands, InteractiveService interactiveService, IServiceProvider services, ILog logger = null)
 {
     Client = client;
     InteractionCommands = interactionCommands;
     InteractiveService  = interactiveService;
     Services            = services;
     Logger = logger;
 }
Beispiel #20
0
 public MiscService(DiscordShardedClient client, IServiceProvider services, NetService net, Random random, RandomService rand, InteractiveService inter)
 {
     _client   = client;
     _services = services;
     _random   = random;
     _net      = net;
     _rand     = rand;
     _inter    = inter;
 }
Beispiel #21
0
        private IServiceProvider BuildServiceProvider(DiscordSocketClient client)
        {
            InteractiveService interactiveService = new InteractiveService(client);

            return(new ServiceCollection()
                   .AddSingleton <InteractiveService>(interactiveService)
                   .AddDbContext <FloofDataContext>()
                   .BuildServiceProvider());
        }
Beispiel #22
0
 public Crime(UserRepository userRepo, GangRepository gangRepo, ModerationService moderationService, GameService gameService, InteractiveService interactiveService, CooldownService CooldownService)
 {
     _userRepo           = userRepo;
     _gangRepo           = gangRepo;
     _moderationService  = moderationService;
     _gameService        = gameService;
     _interactiveService = interactiveService;
     _cooldownService    = CooldownService;
 }
Beispiel #23
0
 public Owners(GuildRepository guildRepo, UserRepository userRepo, GangRepository gangRepo, RankHandler rankHandler, GameService gameService, InteractiveService interactiveService)
 {
     _guildRepo          = guildRepo;
     _gangRepo           = gangRepo;
     _userRepo           = userRepo;
     _RankHandler        = rankHandler;
     _gameService        = gameService;
     _interactiveService = interactiveService;
 }
 public override void Stop(ImageViewer imageViewer)
 {
     if (IsStarted)
     {
         InteractiveService service = base.InteractiveService;
         service.Tap -= new EventHandler <InteractiveEventArgs>(service_Tap);
         base.Stop(imageViewer);
     }
 }
 public ModerationModule(DataService data, DiscordSocketClient client, LogHandler log, GoogleCalendar calendar,
                         PlaytestService playtestService, InteractiveService interactive)
 {
     _playtestService = playtestService;
     _calendar        = calendar;
     _data            = data;
     _client          = client;
     _log             = log;
     _interactive     = interactive;
 }
Beispiel #26
0
        public static async Task <IUserMessage> NewSendPaginatedMessageAsync(this InteractiveService IS,
                                                                             SocketCommandContext context,
                                                                             PaginatedMessage pager,
                                                                             ICriterion <SocketReaction> criterion = null)
        {
            var callback = new CustomPMC(IS, context, pager, criterion);
            await callback.DisplayAsync().ConfigureAwait(false);

            return(callback.Message);
        }
Beispiel #27
0
 public PaginationWithAction(ConfigurationStep step, ConfigurationStep parent, System.Collections.Generic.List <IPaginatable> elements,
                             bool confirmation, SocketCommandContext context, InteractiveService interactive)
 {
     this.step              = step;
     this.parent            = parent;
     this.elements          = elements;
     this.needsConfirmation = confirmation;
     this.context           = context;
     this.interactive       = interactive;
 }
Beispiel #28
0
 public PaginatedMessageCallback(InteractiveService interactive,
                                 EspeonContext sourceContext,
                                 PaginatedMessage pager, ICriterion <Emoji> criterion = null)
 {
     _interactive = interactive;
     Context      = sourceContext;
     Criterion    = criterion ?? new EmptyCriterion <Emoji>();
     _pager       = pager;
     _pages       = _pager.Pages.Count();
 }
 /// <summary>
 /// Sends a confirmation message, and deletes it after a specified timeout.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="interactivity">The interactivity service.</param>
 /// <param name="contents">The contents of the message.</param>
 /// <param name="timeout">The timeout after which the message should be deleted.</param>
 public async Task SendConfirmationAndDeleteAsync
 (
     [NotNull] SocketCommandContext context,
     [NotNull] InteractiveService interactivity,
     [NotNull] string contents,
     [CanBeNull] TimeSpan?timeout = null
 )
 {
     await SendEmbedAndDeleteAsync(context, interactivity, Color.DarkPurple, contents, timeout);
 }
Beispiel #30
0
        public async Task InitializeAsync()
        {
            _ = PublicVariables.Colors;
            _configuration = ConfigurationService.LoadNewConfig();
            _database      = new DatabaseService(_configuration);
            _http          = new HttpClient();
            _client        = new DiscordShardedClient(new DiscordSocketConfig
            {
                AlwaysDownloadUsers = true,
                DefaultRetryMode    = RetryMode.AlwaysRetry,
                LogLevel            = LogSeverity.Info,
                MessageCacheSize    = 2048,
                TotalShards         = _configuration.ShardCount
            });
            _commands = new CommandService(new CommandServiceConfig
            {
                CaseSensitiveCommands = false,
                LogLevel       = LogSeverity.Info,
                DefaultRunMode = RunMode.Sync
            });
            _interactive = new InteractiveService(_client);
            _services    = new ServiceCollection()
                           .AddSingleton(_client)
                           .AddSingleton(_commands)
                           .AddSingleton(_configuration)
                           .AddSingleton(_database)
                           .AddSingleton(_interactive)
                           .AddSingleton(_http)
                           .AddSingleton(new Giphy(_configuration.GiphyApiKey))
                           .AddSingleton <StatisticsService>()
                           .AddSingleton <Random>()
                           .AddSingleton <LogService>()
                           .AddSingleton <CachingService>()
                           .AddSingleton <ServerService>()
                           .AddSingleton <NsfwService>()
                           .BuildServiceProvider();
            _services.GetService <LogService>();
            _services.GetService <StatisticsService>();
            _client.MessageReceived += MessageReceived;
            _client.ReactionAdded   += ReactionAdded;
            _client.Log             += Log;
            _commands.Log           += Log;
            _client.ShardReady      += Ready;

            await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services);

            Console.WriteLine($"{_commands.Commands.Count()} commands | {_commands.Modules.Count()} modules");

            await _client.LoginAsync(TokenType.Bot, _configuration.BotToken);

            await _client.StartAsync();

            await Task.Delay(-1);
        }