Esempio n. 1
0
        static void Main(string[] args)
        {
            Startup startup = new Startup();
            var botConfiguration = startup.Configure();
            channelbotConfiguration = new ChannelConfigurationService(botConfiguration);
            botConfiguration.Channels = channelbotConfiguration.LoadChannels();

            var client = new HttpClient();
            var apiUtilityService = new ApiUtilityService(botConfiguration);

            chatResponseService = new ChatResponseService(client, apiUtilityService, botConfiguration);
            chatUpdateService = new ChatUpdateService(client, apiUtilityService, botConfiguration);
            userDetailService = new UserDetailService(client, botConfiguration);
            reactionService = new ReactionService(client, apiUtilityService, botConfiguration);
            reactionAddService = new ReactionAddService(client, apiUtilityService, botConfiguration);

            discord = new DiscordClient(new DiscordConfiguration
            {
                Token = botConfiguration.Token,
                TokenType = TokenType.Bot
            });

            botUtilityService = new BotUtilityService(discord, botConfiguration);
            commandService = new CommandService(botConfiguration, channelbotConfiguration);
            botReactionService = new BotReactionService(botConfiguration, new EmojiService(discord));
            requiredPropertyResponseService = new RequiredPropertyResponseService(discord, botUtilityService);

            MainAsync(args).ConfigureAwait(false).GetAwaiter().GetResult();
        }
Esempio n. 2
0
        public async Task ChangeReactionAsyncShouldChangeToDislike()
        {
            var list = new List <PostReact>()
            {
                new PostReact
                {
                    IsLiked = false,
                    PostId  = 1,
                    UserId  = "user1",
                },
                new PostReact
                {
                    IsLiked = true,
                    PostId  = 2,
                    UserId  = "user1",
                },
                new PostReact
                {
                    IsLiked = false,
                    PostId  = 3,
                    UserId  = "user2",
                },
            };

            var repository = new Mock <IRepository <PostReact> >();

            repository.Setup(r => r.All()).Returns(() => list.AsQueryable());
            var service = new ReactionService(repository.Object);

            var react = service.ChangeReactionAsync(2, "user1", "Dislike");

            Assert.False(list[2].IsLiked);
            repository.Verify(x => x.All(), Times.Once);
        }
 public PostReactsWidgetViewComponent(PostReactService postReactService,
                                      ReactionService reactionService, UserInfoService userInfoService)
 {
     this.postReactService = postReactService;
     this.reactionService  = reactionService;
     this.userInfoService  = userInfoService;
 }
Esempio n. 4
0
        public void GetPostReactShouldReturnCorrectReact()
        {
            var list = new List <PostReact>()
            {
                new PostReact
                {
                    IsLiked = false,
                    PostId  = 1,
                    UserId  = "user1",
                },
                new PostReact
                {
                    IsLiked = true,
                    PostId  = 2,
                    UserId  = "user1",
                },
            };

            var repository = new Mock <IRepository <PostReact> >();

            repository.Setup(r => r.All()).Returns(() => list.AsQueryable());
            var service = new ReactionService(repository.Object);

            var react = service.GetPostReact(2, "user1");

            Assert.True(react.IsLiked);
            Assert.Equal(2, react.PostId);
            Assert.Equal("user1", react.UserId);
            repository.Verify(x => x.All(), Times.Once);
        }
 public CommReactsWidgetViewComponent(CommReactService commReactService,
                                      ReactionService reactionService, UserInfoService userInfoService)
 {
     this.commReactService = commReactService;
     this.reactionService  = reactionService;
     this.userInfoService  = userInfoService;
 }
Esempio n. 6
0
 public ReactionsController(PostReactService postReactService,
                            CommReactService commReactService, ReactionService reactionService)
 {
     this.postReactService = postReactService;
     this.commReactService = commReactService;
     this.reactionService  = reactionService;
 }
Esempio n. 7
0
 /// <summary>
 /// Constructs the <see cref="HelpService"/>.
 /// </summary>
 public HelpService(DiscordBotServiceContainer services,
                    ConfigParserService configParser,
                    ReactionService reactions)
     : base(services)
 {
     this.configParser = configParser;
     this.reactions    = reactions;
 }
 public ReactionModule(
     ReactionService reactionService,
     DiscordSocketClient client,
     ILogger <ReactionModule> logger)
 {
     _reactionService = reactionService;
     _client          = client;
     _logger          = logger;
 }
Esempio n. 9
0
 public HelpModule(DiscordBotServiceContainer services,
                   ReactionService reactions,
                   HelpService help,
                   ConfigParserService configParser)
     : base(services)
 {
     this.reactions    = reactions;
     this.help         = help;
     this.configParser = configParser;
 }
Esempio n. 10
0
 public BotService(ConversationService conversationService, AnalyzationService analyzationService, ResponseService responseService, ReactionService reactionService, ConversationUpdateService conversationUpdateService, UserService.UserService userService, UpdateDatabasesService updateDatabasesService)
 {
     _conversationService       = conversationService;
     _analyzationService        = analyzationService;
     _responseService           = responseService;
     _reactionService           = reactionService;
     _covnersationUpdateService = conversationUpdateService;
     _userService            = userService;
     _updateDatabasesService = updateDatabasesService;
 }
Esempio n. 11
0
        public void GetUsersWhoDislikedPostShouldReturnCorrectNumberOfUsers()
        {
            var list = new List <PostReact>()
            {
                new PostReact
                {
                    IsLiked = false,
                    PostId  = 1,
                    User    = new ApplicationUser
                    {
                        UserName = "******",
                    },
                },
                new PostReact
                {
                    IsLiked = true,
                    PostId  = 2,
                    User    = new ApplicationUser
                    {
                        UserName = "******",
                    },
                },
                new PostReact
                {
                    IsLiked = false,
                    PostId  = 1,
                    User    = new ApplicationUser
                    {
                        UserName = "******",
                    },
                },
                new PostReact
                {
                    IsLiked = true,
                    PostId  = 1,
                    User    = new ApplicationUser
                    {
                        UserName = "******",
                    },
                },
            };

            var repository = new Mock <IRepository <PostReact> >();

            repository.Setup(r => r.AllAsNoTracking()).Returns(() => list.AsQueryable());
            var service = new ReactionService(repository.Object);

            var reacts = service.GetUsersWhoDislikedPost(1).ToList();

            Assert.Equal(2, reacts.Count());
            Assert.Equal(list[0].User.UserName, reacts[0].User);
            Assert.Equal(list[2].User.UserName, reacts[1].User);
            repository.Verify(x => x.AllAsNoTracking(), Times.Once);
        }
Esempio n. 12
0
        public async Task ServiceInit()
        {
            SchedulerService.Init(Client.GetGuild(setting.ServerId).GetTextChannel(setting.ChannelId));
            SchedulerService.GetInstance().Start();

            ReactionService.Init();

            Provider = new ServiceCollection().BuildServiceProvider();
            Commands = new CommandService();
            await Commands.AddModulesAsync(Assembly.GetEntryAssembly(), Provider);
        }
Esempio n. 13
0
 // GET: Admin/Home
 public ActionResult Index()
 {
     return(View(new Models.HomeIndexViewModel
     {
         AccountCount = UserService.Count(),
         ReactionCount = ReactionService.Count(),
         UploadCount = FileService.Count(),
         DownloadCount = FileService.DownloadCount(),
         GameVariants = GameTypeService.SearchVariants("", "release", false, null, null, null).Take(5),
         ForgeVariants = GameMapService.SearchVariants("", "release", false, null, null, null).Take(5),
     }));
 }
Esempio n. 14
0
 public HomeController(ILogger <HomeController> logger,
                       SearchService searchService,
                       FriendsService friendsService,
                       BlockService blockService,
                       ReactionService reactionService)
 {
     _logger              = logger;
     this.searchService   = searchService;
     this.friendsService  = friendsService;
     this.blockService    = blockService;
     this.reactionService = reactionService;
 }
Esempio n. 15
0
        public async Task TicTacToeAsync(IGuildUser user)
        {
            var message = await ReplyAsync($"<@{Context.User.Id}> Challenged <@{user.Id}> to TicTacToe.");

            Emoji[] emotes = new Emoji[9] {
                new Emoji("\u0031\uFE0F\u20E3"), new Emoji("\u0032\uFE0F\u20E3"), new Emoji("\u0033\uFE0F\u20E3"), new Emoji("\u0034\uFE0F\u20E3"), new Emoji("\u0035\uFE0F\u20E3"), new Emoji("\u0036\uFE0F\u20E3"), new Emoji("\u0037\uFE0F\u20E3"), new Emoji("\u0038\uFE0F\u20E3"), new Emoji("\u0039\uFE0F\u20E3")
            };
            await message.AddReactionsAsync(emotes);

            var gameState = new TicTacToeGameState(message, Context.User.Id, user.Id);

            ReactionService.AddTicTacToe(gameState);
            await message.ModifyAsync(m => { m.Content = gameState.ToString(); });
        }
Esempio n. 16
0
        public void GetUsersWhoLikedPostShouldReturnZeroIfThereArentSuch()
        {
            var list = new List <PostReact>();

            var repository = new Mock <IRepository <PostReact> >();

            repository.Setup(r => r.AllAsNoTracking()).Returns(() => list.AsQueryable());
            var service = new ReactionService(repository.Object);

            var reacts = service.GetUsersWhoLikedPost(1).ToList();

            Assert.Empty(reacts);
            repository.Verify(x => x.AllAsNoTracking(), Times.Once);
        }
Esempio n. 17
0
        public MainPageDataViewComponent(SearchService searchService, FriendsService friendsService,
                                         BlockService blockService, ReactionService reactionService,
                                         UserBlogService userBlogService, SectionsService sectionsService,
                                         BlogService blogService, UserInfoService userInfoService)
        {
            this.searchService   = searchService;
            this.friendsService  = friendsService;
            this.blockService    = blockService;
            this.reactionService = reactionService;
            this.userBlogService = userBlogService;
            this.sectionsService = sectionsService;
            this.blogService     = blogService;
            this.userInfoService = userInfoService;

            this.randomizer = new Random();
        }
Esempio n. 18
0
        public async Task CommandRecieved(SocketMessage messageParam)
        {
            var message = messageParam as SocketUserMessage;

            if (message == null)
            {
                return;
            }

            log.Debug("#{0} {1}: {2}", message.Channel.Name, message.Author.Username, message);
            if (message?.Author.IsBot ?? true)
            {
                return;
            }

            if (message.Content.StartsWith(Client.CurrentUser.Mention))
            {
                await ReactionService.Reaction(message.Channel, message.Author,
                                               getArgsFromMention(message.Content, Client.CurrentUser));

                return;
            }

            int argPos = 0;

            if (!message.HasCharPrefix('/', ref argPos))
            {
                return;
            }

            var     context = new CommandContext(Client, message);
            IResult result  = await Commands.ExecuteAsync(context, argPos, Provider);

            if (!result.IsSuccess)
            {
                await context.Channel.SendMessageAsync(getErrorMessage(result));
            }
        }
Esempio n. 19
0
        public async Task RunBotASync()
        {
            _configuration = new ConfigurationBuilder()
                             .SetBasePath(Directory.GetCurrentDirectory())
                             .AddJsonFile("appsettings.json", false)
                             .Build();

            var config = new DiscordSocketConfig {
                MessageCacheSize = 100, LogLevel = LogSeverity.Verbose
            };

            _client    = new DiscordSocketClient(config);
            _commands  = new CommandService();
            _reactions = new ReactionService();

            _services = new ServiceCollection()
                        .AddSingleton(_client)
                        .AddSingleton(_commands)
                        .AddSingleton(_reactions)
                        .AddSingleton(_configuration)
                        .AddLogging(builder => builder.AddSerilog(dispose: true))
                        .AddEntityFrameworkSqlServer()
                        .AddDbContext <GameBotDbContext>(options =>
                                                         options.UseNpgsql(_configuration.GetConnectionString("GameBotDb")))
                        .BuildServiceProvider();

            var token = _configuration.GetSection("DiscordToken").Value;

            _client.Log += _client_Log;

            await RegisterCommandsAsync();

            await _client.LoginAsync(TokenType.Bot, token);

            await _client.StartAsync();

            await Task.Delay(-1);
        }
Esempio n. 20
0
        public async Task CreateReactShouldAddTheNewReact()
        {
            var list = new List <PostReact>()
            {
                new PostReact
                {
                    IsLiked = false,
                    PostId  = 1,
                    UserId  = "user1",
                },
            };

            var repository = new Mock <IRepository <PostReact> >();

            repository.Setup(r => r.AddAsync(It.IsAny <PostReact>())).Callback((PostReact react) => list.Add(react));
            var service = new ReactionService(repository.Object);

            var react = service.CreateReact(2, "user1", true);

            Assert.True(list[1].IsLiked);
            Assert.Equal(2, list[1].PostId);
            Assert.Equal("user1", list[1].UserId);
            repository.Verify(x => x.AddAsync(It.IsAny <PostReact>()), Times.Once);
        }
Esempio n. 21
0
 public DepressedHandler(DiscordSocketClient client,
                         CommandService commandService,
                         LoggingService loggingService,
                         AutoResponseService autoResponseService,
                         DadService dadService,
                         ReactionService reactionService,
                         ModerationService moderationService,
                         OwoService owoService,
                         CountingService countingService,
                         ConfessionalService confessionalService,
                         IServiceProvider serviceProvider)
 {
     _client       = client;
     _service      = commandService;
     _logger       = loggingService;
     _autoResponse = autoResponseService;
     _dad          = dadService;
     _reaction     = reactionService;
     _moderation   = moderationService;
     _owo          = owoService;
     _counting     = countingService;
     _confessional = confessionalService;
     _provider     = serviceProvider;
 }
 public FloaterReactionsViewComponent(ReactionService reactionService)
 {
     this.reactionService = reactionService;
 }
Esempio n. 23
0
 public ShineHelpful(IServiceProvider _services)
 {
     _reaction = _services.GetRequiredService <ReactionService>();
 }
Esempio n. 24
0
 private async Task HandleReactionAdded(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
 {
     await ReactionService.HandleReactionAdded(channel, reaction);
 }
Esempio n. 25
0
 public async Task SendReaction(string reaction)
 {
     ReactionService.SendReaction(reaction);
 }
Esempio n. 26
0
 private static async Task ReactionAddedHandler(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
 {
     SocketTextChannel guildChannel = channel as SocketTextChannel;
     await ReactionService.HandleReactionAdded(guildChannel, reaction);
 }