protected override void OnMessage(WebSocketSharp.MessageEventArgs e) { JObject obj = JsonConvert.DeserializeObject <JObject>(e.Data); switch (obj.GetValue("op").ToObject <ListOpcode>()) { case ListOpcode.Token: TokenRequest tokenReq = obj.ToObject <TokenRequest>(); DiscordClient client = Server.Bots.First(c => c.Client.User.Id == tokenReq.Id); tokenReq.Token = client.Token; tokenReq.At = client.User.ToString(); Send(tokenReq); break; case ListOpcode.BotModify: ModRequest modReq = obj.ToObject <ModRequest>(); if (modReq.SetAll) { foreach (var bot in new List <RaidBotClient>(Server.Bots)) { ModifyUser(bot, modReq); } } else { RaidBotClient bot = Server.Bots.First(c => c.Client.User.Id == modReq.Id); ModResponse resp = new ModResponse { At = bot.Client.User.ToString() }; resp.Success = ModifyUser(bot, modReq); Send(resp); } break; case ListOpcode.BotInfo: BotInfoRequest infoReq = JsonConvert.DeserializeObject <BotInfoRequest>(e.Data); SocketServer.Broadcast("/list", BotInfo.FromClient(Server.Bots.First(b => b.Client.User.Id == infoReq.Id), infoReq.GetGuildsAndFriends)); break; } }
protected override void OnMessage(WebSocketSharp.MessageEventArgs e) { JObject obj = JsonConvert.DeserializeObject <JObject>(e.Data); switch (obj.GetValue("op").ToObject <ReconOpcode>()) { case ReconOpcode.StartRecon: Task.Run(() => { var req = obj.ToObject <StartReconRequest>(); int bots = 0; Guild guild = null; foreach (var bot in Server.Bots) { try { if (bot.SocketClient) { if (guild == null) { guild = bot.Client.GetGuild(req.GuildId); bots++; } else { if (bot.Guilds.Where(g => g.Id == req.GuildId).Count() > 0) { bots++; } } } else { guild = bot.Client.GetGuild(req.GuildId); bots++; } } catch { } } if (guild == null) { SocketServer.Broadcast("/recon", new ReconRequest(_id, ReconOpcode.ReconFailed)); return; } ServerRecon recon = new ServerRecon(_id) { Name = guild.Name, Description = guild.Description ?? "No description", Region = guild.Region, VerificationLevel = guild.VerificationLevel.ToString(), VanityInvite = guild.VanityInvite ?? "None", BotsInGuild = $"{bots.ToString()}/{Server.Bots.Count}" }; foreach (var role in guild.Roles.Where(r => r.Mentionable)) { recon.Roles.Add(new NameId(role.Name, role.Id)); } foreach (var emoji in guild.Emojis.Distinct()) { recon.Emojis.Add(new NameId(emoji.Name, emoji.Id.Value)); } SocketServer.Broadcast("/recon", recon); }); break; } }
//Issue: Currently try catch blocks here are quite lazy. might wanna add some stuff public async void StartAsync() { await Task.Run(() => { foreach (var bot in Server.Bots) { if (_options.RemoveGuilds) { foreach (var guild in bot.Client.GetGuilds()) { try { if (guild.Owner) { guild.Delete(); } else { guild.Leave(); } Thread.Sleep(100); } catch { } } } if (_options.RemoveRelationships) { try { foreach (var relationship in bot.Client.GetRelationships()) { relationship.Remove(); Thread.Sleep(100); } } catch { } } if (_options.RemoveDMs) { try { foreach (var dm in bot.Client.GetPrivateChannels()) { dm.Leave(); Thread.Sleep(100); } } catch { } } if (_options.ResetProfile) { try { if (bot.Client.User.EmailVerified) { bot.Client.User.SetHypesquad(Hypesquad.None); } if (bot.Client.User.Avatar != null) { bot.Client.User.ChangeProfile(new UserProfileUpdate() { Avatar = null }); } } catch { } try { foreach (var connection in bot.Client.GetProfile(bot.Client.User.Id).ConnectedAccounts) { bot.Client.RemoveConnectedAccount(connection.Type, connection.Id); Thread.Sleep(100); } } catch { } } SocketServer.Broadcast("/cleaner", new AccountCleanedRequest(bot)); } Finished = true; SocketServer.Broadcast("/cleaner", new CleanerRequest(CleanerOpcode.CleanerFinished)); }); }
public static void Broadcast <T>() where T : DashboardInnerRequest, new() { SocketServer.Broadcast("/dashboard", new DashboardRequest <T>()); }
public static void UpdateList(ListAction action, List <RaidBotClient> bots) { SocketServer.Broadcast("/list", new ListRequest(action, bots)); }
public async void StartAsync() { await Task.Run(() => { if (Server.Bots.Count == 0) { SocketServer.Broadcast("/checker", new CheckerErrorRequest("notokens")); Finished = true; return; } SocketServer.Broadcast("/checker", new CheckerStartedRequest()); List <RaidBotClient> uncheckedClients = new List <RaidBotClient>(Server.Bots); foreach (var client in new List <RaidBotClient>(uncheckedClients)) { BotCheckedRequest req = new BotCheckedRequest(client); try { client.Client.JoinGuild("a"); } catch (DiscordHttpException e) { if (e.Code == DiscordError.UnknownInvite || e.Code == DiscordError.MaximumGuilds) { req.Valid = true; } else { if (e.Code == DiscordError.AccountUnverified) { File.AppendAllText(_checkDir + "/Locked.txt", client.Client.Token + "\n"); } else { File.AppendAllText(_checkDir + "/Invalid.txt", client.Client.Token + "\n"); } } } catch (JsonReaderException) { SocketServer.Broadcast("/checker", new CheckerErrorRequest("ratelimit")); List <string> uncheckedTokens = new List <string>(); foreach (var acc in uncheckedClients) { uncheckedTokens.Add(acc.Client.Token); } File.WriteAllText(_checkDir + "/Unchecked.txt", string.Join("\n", uncheckedTokens)); Finished = true; break; } uncheckedClients.Remove(client); if (req.Valid) { File.AppendAllText(_checkDir + "/Valid.txt", client.Client.Token + "\n"); Progress.Valid++; } else { Server.Bots.Remove(client); SocketServer.Broadcast("/list", new ListRequest(ListAction.Remove, client)); Progress.Invalid++; } req.Progress = Progress; SocketServer.Broadcast("/checker", req); } SocketServer.Broadcast("/checker", new CheckerRequest(CheckerOpcode.Done)); Finished = true; }); }