private async Task HandleUserJoin(SocketGuildUser u) { await Logger.DetailedLog(u.Guild, "Event", "User Joined", "User", $"{u}", u.Id, new Color(12, 255, 129), false); using (var db = new DbContext()) { var guildRepo = new GuildRepository(db); var muteRepo = new MuteRepository(db); var user = u as IGuildUser; var mutedRole = user.Guild.GetRole((await guildRepo.FetchGuildAsync(user.Guild.Id)).MutedRoleId); if (mutedRole != null && u.Guild.CurrentUser.GuildPermissions.ManageRoles && mutedRole.Position < u.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position) { await RankHandler.Handle(u.Guild, u.Id); if (await muteRepo.IsMutedAsync(user.Id, user.Guild.Id) && mutedRole != null && user != null) { await user.AddRoleAsync(mutedRole); } } if (Config.BLACKLISTED_IDS.Any(x => x == u.Id)) { if (u.Guild.CurrentUser.GuildPermissions.BanMembers && u.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position > u.Roles.OrderByDescending(x => x.Position).First().Position&& u.Guild.OwnerId != u.Id) { await u.Guild.AddBanAsync(u); } } } }
public Owners(GuildRepository guildRepo, UserRepository userRepo, GangRepository gangRepo, RankHandler rankHandler) { _guildRepo = guildRepo; _gangRepo = gangRepo; _userRepo = userRepo; _rankHandler = rankHandler; }
public static async Task EditCashAsync(SocketCommandContext context, ulong userId, double change) { var cash = FetchUser(userId, context.Guild.Id).Cash; DEABot.Users.UpdateOne(y => y.UserId == userId && y.GuildId == context.Guild.Id, DEABot.UserUpdateBuilder.Set(x => x.Cash, change + cash)); await RankHandler.Handle(context.Guild, userId); }
public General(UserRepository userRepo, GuildRepository guildRepo, GangRepository gangRepo, RankHandler rankHandler, Item[] items) { _userRepo = userRepo; _guildRepo = guildRepo; _gangRepo = gangRepo; _rankHandler = rankHandler; _items = items; }
public static async Task EditCashAsync(SocketCommandContext context, ulong userId, double change) { var user = await FetchUserAsync(userId, context.Guild.Id); user.Cash = Math.Round(user.Cash + change, 2); await BaseRepository <User> .UpdateAsync(user); await RankHandler.Handle(context.Guild, userId); }
public General(UserRepository userRepo, GuildRepository guildRepo, GangRepository gangRepo, RankHandler rankHandler, GameService gameService, CooldownService cooldownService) { _userRepo = userRepo; _guildRepo = guildRepo; _gangRepo = gangRepo; _RankHandler = rankHandler; _gameService = gameService; _cooldownService = cooldownService; }
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 UserJoined(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; _userRepo = _serviceProvider.GetService <UserRepository>(); _guildRepo = serviceProvider.GetService <GuildRepository>(); _muteRepo = serviceProvider.GetService <MuteRepository>(); _blacklistRepo = serviceProvider.GetService <BlacklistRepository>(); _rankHandler = serviceProvider.GetService <RankHandler>(); _client = _serviceProvider.GetService <DiscordSocketClient>(); _client.UserJoined += HandleUserJoined; }
public async Task EditOtherCashAsync(SocketCommandContext context, ulong userId, float change) { var user = await FetchUser(userId); user.Cash = (float)Math.Round(user.Cash + change, 2); await UpdateAsync(user); if ((context.Guild.CurrentUser as IGuildUser).GuildPermissions.ManageRoles) { await RankHandler.Handle(context.Guild, userId); } }
private async Task HandleUserJoin(SocketGuildUser u) { await Logger.DetailedLog(u.Guild, "Event", "User Joined", "User", $"{u}", u.Id, new Color(12, 255, 129), false); var user = u as IGuildUser; var mutedRole = user.Guild.GetRole(((GuildRepository.FetchGuild(user.Guild.Id)).MutedRoleId)); if (mutedRole != null && u.Guild.CurrentUser.GuildPermissions.ManageRoles && mutedRole.Position < u.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position) { await RankHandler.Handle(u.Guild, u.Id); if (MuteRepository.IsMuted(user.Id, user.Guild.Id) && mutedRole != null && user != null) { await user.AddRoleAsync(mutedRole); } } }
private async Task HandleUserJoining(SocketGuildUser arg) { if (arg.IsBot) { await(arg as IGuildUser).AddRoleAsync(arg.Guild.Roles.FirstOrDefault(x => x.Name == "Bot")); await Utilities.SendEmbed(arg.Guild.GetTextChannel(294699220743618561), "New Bot", $"The {arg.Username} bot has been added to the server.", Colors.Green, "", arg.GetAvatarUrl()); return; } string desc = $"{arg} has joined the server."; if (UserAccounts.GetAccount(arg).level != 0) { string rank = RankHandler.LevelToRank(UserAccounts.GetAccount(arg).level); await(arg as IGuildUser).AddRoleAsync(arg.Guild.Roles.FirstOrDefault(x => x.Name == rank)); desc += $" Their rank has been restored to {rank}."; } await Utilities.SendEmbed(arg.Guild.GetTextChannel(294699220743618561), "New User", desc, Colors.Green, "", arg.GetAvatarUrl()); }
static Config() { RankHandler.Start(); if (!Directory.Exists("Resources")) { Directory.CreateDirectory("Resources"); } // If the file doesn't exist, WriteAllText with the json // If it exists, deserialize the json into the corresponding object // config.json if (!File.Exists("Resources/config.json")) { File.WriteAllText("Resources/config.json", JsonConvert.SerializeObject(bot, Formatting.Indented)); } else { bot = JsonConvert.DeserializeObject <BotConfig>(File.ReadAllText("Resources/config.json")); } // trivia_questions.json if (!File.Exists("Resources/trivia_questions.json")) { File.WriteAllText("Resources/trivia_questions.json", JsonConvert.SerializeObject(triviaQuestions, Formatting.Indented)); } else { triviaQuestions = JsonConvert.DeserializeObject <TriviaQuestions>(File.ReadAllText("Resources/trivia_questions.json")); } // whoSaidIt.json if (!File.Exists("Resources/whoSaidIt.json")) { File.WriteAllText("Resources/whoSaidIt.json", JsonConvert.SerializeObject(whoSaidItResources, Formatting.Indented)); } else { whoSaidItResources = JsonConvert.DeserializeObject <whoSaidItResources>(File.ReadAllText("Resources/whoSaidIt.json")); } }
/** * 排行 * @param selfRank 自己排名 * @param page 页面 * @param rankType 排行版类型 * @param rankDataList 排行数据 */ public void GC_COMMON_RANK(InputMessage data) { int i, size; long selfRank = data.GetLong(); int page = data.GetInt(); int rankType = data.GetInt(); ArrayList rankDataList = new ArrayList(); size = data.GetShort(); for (i = 0; i < size; i++) { RankData rankDataList_Datas = new RankData(); rankDataList_Datas.uId = data.GetLong(); rankDataList_Datas.name = data.GetString(); //名字 rankDataList_Datas.img = data.GetString(); //图片 rankDataList_Datas.score = data.GetLong(); rankDataList.Add(rankDataList_Datas); } RankHandler.Instance().GC_COMMON_RANK(selfRank, page, rankType, rankDataList); }
public async Task Rank(IGuildUser userToView = null) { userToView = userToView ?? Context.User as IGuildUser; List <User> users = (await UserRepository.AllAsync(Context.Guild.Id)).OrderByDescending(x => x.Cash).ToList(); IRole rank = null; rank = await RankHandler.FetchRank(Context); var builder = new EmbedBuilder() { Title = $"Ranking of {userToView}", Color = new Color(0x00AE86), Description = $"Balance: {(await UserRepository.FetchUserAsync(Context)).Cash.ToString("C", Config.CI)}\n" + $"Position: #{users.FindIndex(x => x.UserId == userToView.Id) + 1}\n" }; if (rank != null) { builder.Description += $"Rank: {rank.Mention}"; } await ReplyAsync("", embed : builder); }
public async Task Rank([Remainder] IGuildUser userToView = null) { userToView = userToView ?? Context.User as IGuildUser; var users = DEABot.Users.Find(y => y.GuildId == Context.Guild.Id).ToList(); var sorted = users.OrderByDescending(x => x.Cash).ToList(); IRole rank = null; rank = RankHandler.FetchRank(Context); var builder = new EmbedBuilder() { Title = $"Ranking of {userToView}", Color = new Color(0x00AE86), Description = $"Balance: {UserRepository.FetchUser(userToView.Id, userToView.GuildId).Cash.ToString("C", Config.CI)}\n" + $"Position: #{sorted.FindIndex(x => x.UserId == userToView.Id) + 1}\n" }; if (rank != null) { builder.Description += $"Rank: {rank.Mention}"; } await ReplyAsync("", embed : builder); }
private async Task HandleCommandAsync(SocketMessage s) { var msg = s as SocketUserMessage; if (msg == null) { return; } PrettyConsole.NewLine(msg.Content); var Context = new SocketCommandContext(_client, msg); PrettyConsole.NewLine((await GuildRepository.FetchGuildAsync(Context.Guild.Id)).Prefix); if (Context.User.IsBot) { return; } if (!(Context.Channel is SocketTextChannel)) { return; } if (!(Context.Guild.CurrentUser as IGuildUser).GetPermissions(Context.Channel as SocketTextChannel).SendMessages) { return; } int argPos = 0; string prefix = (await GuildRepository.FetchGuildAsync(Context.Guild.Id)).Prefix; if (msg.HasStringPrefix(prefix, ref argPos) || msg.HasMentionPrefix(_client.CurrentUser, ref argPos)) { PrettyConsole.Log(LogSeverity.Debug, $"Guild: {Context.Guild.Name}, User: {Context.User}", msg.Content); var result = await _service.ExecuteAsync(Context, argPos, _map); if (!result.IsSuccess && result.Error != CommandError.UnknownCommand) { var cmd = _service.Search(Context, argPos).Commands.First().Command; if (result.ErrorReason.Length == 0) { return; } switch (result.Error) { case CommandError.BadArgCount: await msg.Channel.SendMessageAsync($"{Context.User.Mention}, You are incorrectly using this command. Usage: `{prefix}{cmd.Remarks}`"); break; case CommandError.ParseFailed: await msg.Channel.SendMessageAsync($"{Context.User.Mention}, Invalid number."); break; default: await msg.Channel.SendMessageAsync($"{Context.User.Mention}, {result.ErrorReason}"); break; } } } else if (msg.ToString().Length >= Config.MIN_CHAR_LENGTH && !msg.ToString().StartsWith(":")) { var user = await UserRepository.FetchUserAsync(Context); var rate = Config.TEMP_MULTIPLIER_RATE; if (DateTimeOffset.Now.Subtract(user.Message).TotalMilliseconds > user.MessageCooldown.TotalMilliseconds) { await UserRepository.ModifyAsync(x => { x.Cash += user.TemporaryMultiplier *user.InvestmentMultiplier; x.TemporaryMultiplier = user.TemporaryMultiplier + rate; x.Message = DateTimeOffset.Now; return(Task.CompletedTask); }, Context); await RankHandler.Handle(Context.Guild, Context.User.Id); } } }
private async Task HandleCommandAsync(SocketMessage s) { SocketUserMessage msg = s as SocketUserMessage; if (msg == null || msg.Author.IsBot) { return; } var context = new SocketCommandContext(_client, msg); await RankHandler.TryToGiveUserXP(context, msg.Author); int argPos = 0; if (msg.HasStringPrefix("!", ref argPos)) { await _service.ExecuteAsync(context, argPos, null, MultiMatchHandling.Exception); } string m = msg.Content.ToLower(); // Answer minigames if (context.Channel.Id == 518846214603669537) { // Answer Trivia if (m == "a" || m == "b" || m == "c" || m == "d") { await MinigameHandler.Trivia.AnswerTrivia((SocketGuildUser)msg.Author, context, m); } // Answer "Who Said It?" int x = 0; if (int.TryParse(m, out x)) { if (x <= 4 && x >= 1 && MinigameHandler.WSI.isGameGoing) { await MinigameHandler.WSI.TryToGuess(context, x); } } } // Print a lennyface if (m.Contains("lennyface")) { await context.Channel.SendMessageAsync("( ͡° ͜ʖ ͡°)"); } // Fix some spelling mistakes for (int i = 0; i < spellingMistakes.Length; i++) { if (m.Contains(spellingMistakes[i])) { await msg.Channel.SendMessageAsync(spellingFix[i] + "*"); } } // Print a DM message to console if (s.Channel.Name.StartsWith("@")) { Console.WriteLine($" ----------\n DIRECT MESSAGE\n From: {s.Channel}\n {s}\n ----------"); } }
private async Task HandleCommandAsync(SocketMessage s) { var msg = s as SocketUserMessage; if (msg == null) { return; } var Context = new SocketCommandContext(_client, msg); if (Context.User.IsBot) { return; } if (!(Context.Channel is SocketTextChannel)) { return; } if (!(Context.Guild.CurrentUser as IGuildUser).GetPermissions(Context.Channel as SocketTextChannel).SendMessages) { return; } int argPos = 0; var guild = GuildRepository.FetchGuild(Context.Guild.Id); string prefix = guild.Prefix; if (msg.HasStringPrefix(prefix, ref argPos) || msg.HasMentionPrefix(_client.CurrentUser, ref argPos)) { PrettyConsole.Log(LogSeverity.Debug, $"Guild: {Context.Guild.Name}, User: {Context.User}", msg.Content); var result = await _service.ExecuteAsync(Context, argPos, _map); if (!result.IsSuccess && result.Error != CommandError.UnknownCommand) { var cmd = _service.Search(Context, argPos).Commands.First().Command; if (result.ErrorReason.Length == 0) { return; } switch (result.Error) { case CommandError.BadArgCount: await msg.Channel.SendMessageAsync($"{Context.User.Mention}, You are incorrectly using this command. Usage: `{prefix}{cmd.Remarks}`"); break; case CommandError.ParseFailed: await msg.Channel.SendMessageAsync($"{Context.User.Mention}, Invalid number."); break; default: await msg.Channel.SendMessageAsync($"{Context.User.Mention}, {result.ErrorReason}"); break; } } } else if (msg.ToString().Length >= Config.MIN_CHAR_LENGTH && !msg.ToString().StartsWith(":")) { var user = UserRepository.FetchUser(Context); if (DateTime.UtcNow.Subtract(user.Message).TotalMilliseconds > user.MessageCooldown) { UserRepository.Modify(DEABot.UserUpdateBuilder.Combine( DEABot.UserUpdateBuilder.Set(x => x.Cash, guild.GlobalChattingMultiplier * user.TemporaryMultiplier * user.InvestmentMultiplier + user.Cash), DEABot.UserUpdateBuilder.Set(x => x.TemporaryMultiplier, user.TemporaryMultiplier + guild.TempMultiplierIncreaseRate), DEABot.UserUpdateBuilder.Set(x => x.Message, DateTime.UtcNow)), Context); await RankHandler.Handle(Context.Guild, Context.User.Id); } } }
public GameSocket(ISerializer serializer) : base(serializer) { _achievementHandler = new AchievementHandler(this); _activityHandler = new ActivityHandler(this); _activityFavorHandler = new ActivityFavorHandler(this); _amuletHandler = new AmuletHandler(this); _arenaHandler = new ArenaHandler(this); _attendanceHandler = new AttendanceHandler(this); _bagHandler = new BagHandler(this); _battleHandler = new BattleHandler(this); _cardHandler = new CardHandler(this); _consignmentLineHandler = new ConsignmentLineHandler(this); _crossServerHandler = new CrossServerHandler(this); _dailyActivityHandler = new DailyActivityHandler(this); _demonTowerHandler = new DemonTowerHandler(this); _equipHandler = new EquipHandler(this); _exchangeHandler = new ExchangeHandler(this); _fashionHandler = new FashionHandler(this); _fightLevelHandler = new FightLevelHandler(this); _fleeHandler = new FleeHandler(this); _friendHandler = new FriendHandler(this); _functionHandler = new FunctionHandler(this); _functionOpenHandler = new FunctionOpenHandler(this); _giftOnlineHandler = new GiftOnlineHandler(this); _goddessHandler = new GoddessHandler(this); _guildBlessHandler = new GuildBlessHandler(this); _guildBossHandler = new GuildBossHandler(this); _guildDepotHandler = new GuildDepotHandler(this); _guildHandler = new GuildHandler(this); _guildShopHandler = new GuildShopHandler(this); _guildTechHandler = new GuildTechHandler(this); _hookSetHandler = new HookSetHandler(this); _interactHandler = new InteractHandler(this); _intergalMallHandler = new IntergalMallHandler(this); _itemHandler = new ItemHandler(this); _leaderBoardHandler = new LeaderBoardHandler(this); _limitTimeActivityHandler = new LimitTimeActivityHandler(this); _mailHandler = new MailHandler(this); _mapHandler = new MapHandler(this); _masteryHandler = new MasteryHandler(this); _medalHandler = new MedalHandler(this); _messageHandler = new MessageHandler(this); _mountHandler = new MountHandler(this); _npcHandler = new NpcHandler(this); _offlineAwardHandler = new OfflineAwardHandler(this); _onlineGiftHandler = new OnlineGiftHandler(this); _payGiftHandler = new PayGiftHandler(this); _petHandler = new PetHandler(this); _petNewHandler = new PetNewHandler(this); _playerHandler = new PlayerHandler(this); _prepaidHandler = new PrepaidHandler(this); _rankHandler = new RankHandler(this); _resourceDungeonHandler = new ResourceDungeonHandler(this); _resourceHandler = new ResourceHandler(this); _rewardHandler = new RewardHandler(this); _saleHandler = new SaleHandler(this); _shopMallHandler = new ShopMallHandler(this); _skillHandler = new SkillHandler(this); _skillKeysHandler = new SkillKeysHandler(this); _soloHandler = new SoloHandler(this); _stealHandler = new StealHandler(this); _sysSetHandler = new SysSetHandler(this); _taskHandler = new TaskHandler(this); _teamHandler = new TeamHandler(this); _tradeHandler = new TradeHandler(this); _treasureHandler = new TreasureHandler(this); _upLevelHandler = new UpLevelHandler(this); _vipHandler = new VipHandler(this); _vitalityHandler = new VitalityHandler(this); _wingHandler = new WingHandler(this); _activityRevelryHandler = new ActivityRevelryHandler(this); _auctionHandler = new AuctionHandler(this); _chatHandler = new ChatHandler(this); _daoYouHandler = new DaoYouHandler(this); _entryHandler = new EntryHandler(this); _roleHandler = new RoleHandler(this); _farmHandler = new FarmHandler(this); _five2FiveHandler = new Five2FiveHandler(this); _guildManagerHandler = new GuildManagerHandler(this); _xianYuanHandler = new XianYuanHandler(this); }
public UserRepository(IMongoCollection <User> users, RankHandler rankHandler) : base(users) { _rankHandler = rankHandler; }