public async void Disconnect() { try { UnregisterEvents(); await DiscordClient.Disconnect(); } catch (Exception exception) { App.LogUnhandledError(exception); } }
public void Start() { _client = new DiscordClient(x=> { x.AppName = "CancerBot"; x.MessageCacheSize = 10; x.EnablePreUpdateEvents = true; }); _client.UsingPermissionLevels((u,c)=> (int)CheckPermLevel(u,c)); _client.UsingCommands(x => { x.PrefixChar = '>'; x.HelpMode = HelpMode.Public; x.ErrorHandler += HandleError; x.AllowMentionPrefix = false; }); var doc = new XmlDocument(); try { doc.Load("commands.xml"); } catch (FileNotFoundException e) { StreamWriter stream = new StreamWriter("commands.xml"); XmlSerializer xml1 = new XmlSerializer(typeof(List<CustomCommand>)); xml1.Serialize(stream, new List<CustomCommand>()); stream.Close(); } catch (XmlException e) { StreamWriter stream = new StreamWriter("commands.xml"); XmlSerializer xml1 = new XmlSerializer(typeof(List<CustomCommand>)); xml1.Serialize(stream, new List<CustomCommand>()); stream.Close(); } CommandService commandService = _client.GetService<CommandService>(); List<CustomCommand> commands = new List<CustomCommand>(); XmlSerializer xml = new XmlSerializer(typeof(List<CustomCommand>)); FileStream file = new FileStream("commands.xml", FileMode.OpenOrCreate); List<CustomCommand> list = (List<CustomCommand>)xml.Deserialize(file); file.Close(); foreach(CustomCommand x in list) { if (forbodens.Contains<string>(x.Name)) { continue; } CommandBuilder b = _client.GetService<CommandService>().CreateCommand(x.Name.ToLower()). Description(x.Contents).Parameter("Cuntents", ParameterType.Unparsed); b.Do(async e => { double deltatime = 5; if (LastCommandTime.ContainsKey(e.User.Id)) { deltatime = (DateTime.Now.Second - LastCommandTime[e.User.Id]); } if (deltatime >= 5) { await e.Channel.SendMessage(x.Contents); } if (LastCommandTime.ContainsKey(e.User.Id)) { LastCommandTime[e.User.Id] = DateTime.Now.Second; } else { LastCommandTime[e.User.Id] = DateTime.Now.Second; } }); try { b._command.IsCustom = true; commandBuilders.Add(x.Name.ToLower(), b); } catch { Console.WriteLine($"Command with name {x.Name} already exists!"); }; } _client.GetService<CommandService>().CreateCommand("test23").Description("Test Command").Do(async e => { await e.Channel.SendMessage("test"); }); //_client.Ready += (s, e) => //{ // _client.FindServers("Discord Bots").First().FindChannels("testing-aloha").First().SendMessage("I'm alive!"); //}; commandService.CreateCommand("changename").Description("Changes Name").Parameter("Name", ParameterType.Unparsed).MinPermissions((int)PermissionLevel.ServerOwner) .Do(async e => { await _client.CurrentUser.Edit("", e.GetArg("Name")); }); // _client.UserBanned += async (s, e) => // { //await e.Server.DefaultChannel.SendMessage(e.User.Name + " was banned forever LUUL"); //}; // _client.UserLeft += async (s, e) => // { //await e.Server.DefaultChannel.SendMessage(e.User.Name + " left FeelsBadMan"); // }; _client.GetService<CommandService>().CreateCommand("8ball").Description("Simple 8ball command").Parameter("memes", ParameterType.Unparsed).Do(async e => { Random rand = new Random(); string output = ""; switch (rand.Next(6)) { case 0: output = "I don't know f****t"; break; case 1: output = "Yes"; break; case 2: output = "No"; break; case 3: output = "Kys"; break; case 4: output = "Ask me later"; break; case 5: output = "Maybe"; break; default: break; } await e.Channel.SendMessage(output); }); Channel Log = _client.GetChannel(192699690473488384); _client.MessageReceived += async (s, e) => { // if (!e.Message.IsAuthor) // { // if (e.Message.Attachments.Length == 0) // { // await e.Channel.SendMessage(DateTime.Now + " UTC - " + e.User.Name + " (" + e.User.Id + "): " + e.Message.Text); // } // else { // await e.Channel.SendMessage(DateTime.Now + " UTC - " + e.User.Name + " (" + e.User.Id + "): " + e.Message.Text+" | Message Contained Attachment: "+e.Message.Attachments[0].Filename+" "+e.Message.Attachments[0].Size+" "+e.Message.Attachments[0].ProxyUrl); // } //} if (e.Message.IsMentioningMe()&&!e.Message.IsAuthor) { if(e.Message.RawText.ToLower().Contains("hi")|| e.Message.RawText.ToLower().Contains("hello")) { await e.Channel.SendMessage($"Hello, <@{e.User.Id}>!"); } if (e.Message.RawText.ToLower().Contains("kys")) { if (e.User.Id == 142291646824841217) { await e.Channel.SendMessage("ok"); System.Threading.Thread.Sleep(1000); _client.Disconnect(); System.Environment.Exit(0); } else { await e.Channel.SendMessage("no u"); } } } }; _client.GetService<CommandService>().CreateCommand("addcustomcommand").Description("Adds Custom Command").Parameter("Name").Parameter("Contents",ParameterType.Unparsed).Do(async e => { if (e.Message.RawText.Contains("@everyone")|| e.Message.RawText.Contains("@here")) { await e.Channel.SendMessage("Don't ping everyone you f****t"); return; } if (e.Message.Attachments.Length > 0) { await e.Channel.SendMessage("I don't support files you retard."); return; } XmlSerializer xml1 = new XmlSerializer(typeof(List<CustomCommand>)); FileStream file1 = new FileStream("commands.xml", FileMode.OpenOrCreate); List<CustomCommand> list1 = (List<CustomCommand>)xml1.Deserialize(file1); file1.Close(); if (list1.Contains(new CustomCommand(e.GetArg("Name").ToLower(), e.GetArg("Contents"))) || forbodens.Contains<string>(e.GetArg("Name"))) { await e.Channel.SendMessage("That already exists."); return; } if (commandBuilders.ContainsKey(e.GetArg("Name").ToLower())) { List<CustomCommand> list2 = list1.Where<CustomCommand>(t => t.Name.ToLower() == e.GetArg("Name").ToLower()).ToList<CustomCommand>(); foreach (CustomCommand g in list2) { list1.Remove(g); list1.Add(new CustomCommand(e.GetArg("Name").ToLower(), e.GetArg("Contents"))); } } else { list1.Add(new CustomCommand(e.GetArg("Name").ToLower(), e.GetArg("Contents"))); } StreamWriter stream = new StreamWriter("commands.xml"); xml1.Serialize(stream, list1); stream.Close(); if (commandBuilders.ContainsKey(e.GetArg("Name").ToLower())) { commandBuilders[e.GetArg("Name").ToLower()].Hide(); Command test = commandBuilders[e.GetArg("Name").ToLower()]._command;//(Command)typeof(CommandBuilder).GetField("_command", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(commandBuilders[e.GetArg("Name").ToLower()]); Action<CommandEventArgs> tes1 = (x => { }); typeof(Command).GetField("_runFunc", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(test, TaskHelper.ToAsync(tes1)); test.IsHidden = true; _client.GetService<CommandService>()._map._items.Remove(e.GetArg("Name").ToLower()); _client.GetService<CommandService>()._categories.FirstOrDefault().Value._items.ToList().ForEach(t => { if (t.Value.Name == test.Text) { _client.GetService<CommandService>()._categories.FirstOrDefault().Value._items.Remove(t.Value.Name); } }); commandBuilders[e.GetArg("Name").ToLower()].Description(e.GetArg("Contents")); Command test1 = commandBuilders[e.GetArg("Name").ToLower()]._command;//(Command)typeof(CommandBuilder).GetField("_command", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(commandBuilders[e.GetArg("Name").ToLower()]); Func<CommandEventArgs,Task> tes11 = (async x => { double deltatime = 5; if (LastCommandTime.ContainsKey(e.User.Id)) { deltatime = (DateTime.Now.Second - LastCommandTime[e.User.Id]); } if (deltatime >= 5) { await x.Channel.SendMessage(e.GetArg("Contents")); } if (LastCommandTime.ContainsKey(e.User.Id)) { LastCommandTime[e.User.Id] = DateTime.Now.Second; } else { LastCommandTime[e.User.Id] = DateTime.Now.Second; } }); commandBuilders[e.GetArg("Name").ToLower()].Do(tes11); } else { CommandBuilder b = _client.GetService<CommandService>().CreateCommand(e.GetArg("Name")).Description(e.GetArg("Contents")).Parameter("Cuntents", ParameterType.Unparsed); b.Do(async x => { await x.Channel.SendMessage(e.GetArg("Contents")); }); b._command.IsCustom = true; commandBuilders.Add(e.GetArg("Name").ToLower(), b); } await e.Channel.SendMessage("Command Made Successfully!"); }); _client.GetService<CommandService>().CreateCommand("delcustomcommand").Description("Deletes a Custom Command").Parameter("Name").Do(async e => { XmlSerializer xml1 = new XmlSerializer(typeof(List<CustomCommand>)); FileStream file1 = new FileStream("commands.xml", FileMode.OpenOrCreate); List<CustomCommand> list1 = (List<CustomCommand>)xml1.Deserialize(file1); file1.Close(); List<CustomCommand> list2 = list1.Where<CustomCommand>(t => t.Name.ToLower() == e.GetArg("Name").ToLower()).ToList<CustomCommand>(); if (list2.Count == 0) { await e.Channel.SendMessage("Command does not exist!"); return; } foreach(CustomCommand x in list2) { list1.Remove(x); } StreamWriter stream = new StreamWriter("commands.xml"); xml1.Serialize(stream, list1); stream.Close(); foreach (Server s in _client.Servers) { ServerConfig config = ServerConfig.GetServerConfig(s.Id); if (config.commandPerms.Where(i => i.Command == e.GetArg("Name")).ToList().Count > 0) { config.commandPerms.Remove(config.commandPerms.Where(i => i.Command == e.GetArg("Name")).FirstOrDefault()); ServerConfig.WriteServerConfig(config); } } commandBuilders[e.GetArg("Name").ToLower()].Hide(); Command test = commandBuilders[e.GetArg("Name").ToLower()]._command;//(Command)typeof(CommandBuilder).GetField("_command", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(commandBuilders[e.GetArg("Name").ToLower()]); Action<CommandEventArgs> tes1 = (x => { }); typeof(Command).GetField("_runFunc", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(test, TaskHelper.ToAsync(tes1)); test.IsHidden = true; _client.GetService<CommandService>()._map._items.Remove(e.GetArg("Name").ToLower()); _client.GetService<CommandService>()._categories.FirstOrDefault().Value._items.ToList().ForEach(t=> { if (t.Value.Name == test.Text) { _client.GetService<CommandService>()._categories.FirstOrDefault().Value._items.Remove(t.Value.Name); } }); commandBuilders.Remove(e.GetArg("Name")); //Console.WriteLine(_client.GetService<CommandService>()._categories.FirstOrDefault().Value._items.FirstOrDefault().); await e.Channel.SendMessage("Command removed Successfully!"); }); _client.GetService<CommandService>().CreateGroup("permissions",e=> { e.CreateGroup("editserver", t => { t.CreateCommand("command").Description("Sets Permission Level for Command").Parameter("Command").Parameter("Level").Do(async u => { ServerConfig config = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.CommandPermission commandperm; if (config.commandPerms.Where(i => i.Command == u.GetArg("Command")).ToList().Count > 0) { commandperm = config.commandPerms.Where(i => i.Command == u.GetArg("Command")).FirstOrDefault(); commandperm.Level = Int32.Parse(u.GetArg("Level")); config.commandPerms[config.commandPerms.IndexOf(config.commandPerms.Where(i => i.Command == u.GetArg("Command")).FirstOrDefault())] = commandperm; } else { config.commandPerms.Add(new ServerConfig.CommandPermission(u.GetArg("Command"), Int32.Parse(u.GetArg("Level")))); } ServerConfig.WriteServerConfig(config); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("removecommand").Description("Removes Permission Level for Command").Parameter("Command").Do(async u => { ServerConfig config = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.CommandPermission commandperm; if (config.commandPerms.Where(i => i.Command == u.GetArg("Command")).ToList().Count > 0) { //commandperm = config.commandPerms.Where(i => i.Command == u.GetArg("Command")).FirstOrDefault(); //commandperm.Level = Int32.Parse(u.GetArg("Level")); config.commandPerms.Remove(config.commandPerms.Where(i => i.Command == u.GetArg("Command")).FirstOrDefault()); } else { //config.commandPerms.Add(new ServerConfig.CommandPermission(u.GetArg("Command"), Int32.Parse(u.GetArg("Level")))); await u.Channel.SendMessage("Permissions UnSucksecksful"); } ServerConfig.WriteServerConfig(config); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("role").Description("Sets Permission Level for Role (has to be EXACT name of role)").Parameter("Command").Parameter("Level").Do(async u => { ServerConfig config = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.RolePermission commandperm; if (config.rolePerms.Where(i => i.Role == u.GetArg("Command")).ToList().Count > 0) { commandperm = config.rolePerms.Where(i => i.Role == u.GetArg("Command")).FirstOrDefault(); commandperm.Level = Int32.Parse(u.GetArg("Level")); config.rolePerms[config.rolePerms.IndexOf(config.rolePerms.Where(i => i.Role == u.GetArg("Command")).FirstOrDefault())] = commandperm; } else { config.rolePerms.Add(new ServerConfig.RolePermission(u.GetArg("Command"), Int32.Parse(u.GetArg("Level")))); } ServerConfig.WriteServerConfig(config); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("removerole").Description("Removes Permission Level for Role (has to be EXACT name of role)").Parameter("Command").Do(async u => { ServerConfig config = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.RolePermission commandperm; if (config.rolePerms.Where(i => i.Role == u.GetArg("Command")).ToList().Count > 0) { config.rolePerms.Remove(config.rolePerms.Where(i => i.Role == u.GetArg("Command")).FirstOrDefault()); } else { //config.rolePerms.Add(new ServerConfig.RolePermission(u.GetArg("Command"), Int32.Parse(u.GetArg("Level")))); await u.Channel.SendMessage("Permissions UnSucksecksful"); } ServerConfig.WriteServerConfig(config); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("user").Description("Sets Permission Level for User (has to be mention)").Parameter("Command").Parameter("Level").Do(async u => { List<char> input = u.GetArg("Command").ToCharArray().ToList(); input.RemoveAt(0); input.RemoveAt(0); input.RemoveAt(input.Count - 1); ulong id = ulong.Parse(String.Concat(input)); ServerConfig config = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.UserPermission commandperm; if (config.userPerms.Where(i => i.UserID == id).ToList().Count > 0) { commandperm = config.userPerms.Where(i => i.UserID == id).FirstOrDefault(); commandperm.Level = Int32.Parse(u.GetArg("Level")); config.userPerms[config.userPerms.IndexOf(config.userPerms.Where(i => i.UserID == id).FirstOrDefault())] = commandperm; } else { config.userPerms.Add(new ServerConfig.UserPermission(id, Int32.Parse(u.GetArg("Level")))); } ServerConfig.WriteServerConfig(config); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("removeuser").Description("Remove Permission Level for User (has to be mention)").Parameter("Command").Do(async u => { List<char> input = u.GetArg("Command").ToCharArray().ToList(); input.RemoveAt(0); input.RemoveAt(0); input.RemoveAt(input.Count - 1); ulong id = ulong.Parse(String.Concat(input)); ServerConfig config = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.UserPermission commandperm; if (config.userPerms.Where(i => i.UserID == id).ToList().Count > 0) { commandperm = config.userPerms.Where(i => i.UserID == id).FirstOrDefault(); config.userPerms.Remove(commandperm); } else { //config.userPerms.Add(new ServerConfig.UserPermission(id, Int32.Parse(u.GetArg("Level")))); await u.Channel.SendMessage("Permissions UnSucksecksful"); } ServerConfig.WriteServerConfig(config); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("commanduser").Description("Blacklists/Whitelists commands for certain user").Parameter("User").Parameter("Command").Parameter("Enabled").Do(async u => { List<char> input = u.GetArg("User").ToCharArray().ToList(); input.RemoveAt(0); input.RemoveAt(0); input.RemoveAt(input.Count - 1); ulong id = ulong.Parse(String.Concat(input)); ServerConfig config = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.UserCommandPermission commandperm; if (config.userCommandPerms.Where(i => (i.Command == u.GetArg("Command") && i.UserID == id)).ToList().Count > 0) { commandperm = config.userCommandPerms.Where(i => i.Command == u.GetArg("Command") && i.UserID == id).FirstOrDefault(); commandperm.UserID = id; commandperm.enabled = bool.Parse(u.GetArg("Enabled")); config.userCommandPerms[config.userCommandPerms.IndexOf(config.userCommandPerms.Where(i => i.Command == u.GetArg("Command") && i.UserID == id).FirstOrDefault())] = commandperm; } else { config.userCommandPerms.Add(new ServerConfig.UserCommandPermission(id, u.GetArg("Command"), bool.Parse(u.GetArg("Enabled")))); } ServerConfig.WriteServerConfig(config); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("removecommanduser").Description("Removes a Blacklist/Whitelist command for certain user").Parameter("User").Parameter("Command").Do(async u => { List<char> input = u.GetArg("User").ToCharArray().ToList(); input.RemoveAt(0); input.RemoveAt(0); input.RemoveAt(input.Count - 1); ulong id = ulong.Parse(String.Concat(input)); ServerConfig config = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.UserCommandPermission commandperm; if (config.userCommandPerms.Where(i => (i.Command == u.GetArg("Command") && i.UserID == id)).ToList().Count > 0) { commandperm = config.userCommandPerms.Where(i => i.Command == u.GetArg("Command") && i.UserID == id).FirstOrDefault(); config.userCommandPerms.Remove(commandperm); } else { await u.Channel.SendMessage("Permissions UnSucksecksful"); } ServerConfig.WriteServerConfig(config); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("commandrole").Description("Blacklists/Whitelists commands for certain role").Parameter("User").Parameter("Command").Parameter("Enabled").Do(async u => { // List<char> input = u.GetArg("User").ToCharArray().ToList(); // input.RemoveAt(0); // input.RemoveAt(0); // input.RemoveAt(input.Count - 1); // ulong id = ulong.Parse(String.Concat(input)); ServerConfig config = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.RoleCommandPermission commandperm; if (config.roleCommandPerms.Where(i => (i.Command == u.GetArg("Command")&&i.Role==u.GetArg("User"))).ToList().Count > 0) { commandperm = config.roleCommandPerms.Where(i => i.Command == u.GetArg("Command") && i.Role == u.GetArg("User")).FirstOrDefault(); commandperm.Role = u.GetArg("User"); commandperm.enabled = bool.Parse(u.GetArg("Enabled")); config.roleCommandPerms[config.roleCommandPerms.IndexOf(config.roleCommandPerms.Where(i => i.Command == u.GetArg("Command") && i.Role == u.GetArg("User")).FirstOrDefault())] = commandperm; } else { config.roleCommandPerms.Add(new ServerConfig.RoleCommandPermission(u.GetArg("User"), u.GetArg("Command"), bool.Parse(u.GetArg("Enabled")))); } ServerConfig.WriteServerConfig(config); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("removecommandrole").Description("Remove a Blacklist/Whitelist command for certain role").Parameter("User").Parameter("Command").Do(async u => { // List<char> input = u.GetArg("User").ToCharArray().ToList(); // input.RemoveAt(0); // input.RemoveAt(0); // input.RemoveAt(input.Count - 1); // ulong id = ulong.Parse(String.Concat(input)); ServerConfig config = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.RoleCommandPermission commandperm; if (config.roleCommandPerms.Where(i => (i.Command == u.GetArg("Command") && i.Role == u.GetArg("User"))).ToList().Count > 0) { commandperm = config.roleCommandPerms.Where(i => i.Command == u.GetArg("Command") && i.Role == u.GetArg("User")).FirstOrDefault(); config.roleCommandPerms.Remove(commandperm); } else { await u.Channel.SendMessage("Permissions UnSucksecksful"); } ServerConfig.WriteServerConfig(config); await u.Channel.SendMessage("Permissions Sucksecksful"); }); }); e.CreateGroup("editchannel", t => { t.CreateCommand("command").Description("Sets Permission Level for Command").Parameter("Command").Parameter("Level").Do(async u => { ServerConfig config1 = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.ChannelPermission config = config1.channelPerms.Where(i => i.ChannelID==u.Channel.Id).FirstOrDefault(); if (config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).ToList().Count == 0) { config = new ServerConfig.ChannelPermission(u.Channel.Id); config1.channelPerms.Add(config); } ServerConfig.CommandPermission commandperm; if (config.commandPerms.Where(i => i.Command == u.GetArg("Command")).ToList().Count > 0) { commandperm = config.commandPerms.Where(i => i.Command == u.GetArg("Command")).FirstOrDefault(); commandperm.Level = Int32.Parse(u.GetArg("Level")); config.commandPerms[config.commandPerms.IndexOf(config.commandPerms.Where(i => i.Command == u.GetArg("Command")).FirstOrDefault())] = commandperm; } else { config.commandPerms.Add(new ServerConfig.CommandPermission(u.GetArg("Command"), Int32.Parse(u.GetArg("Level")))); } config1.channelPerms[config1.channelPerms.FindIndex(y => y.ChannelID == u.Channel.Id)] = config; ServerConfig.WriteServerConfig(config1); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("removecommand").Description("Removes Permission Level for Command").Parameter("Command").Do(async u => { ServerConfig config1 = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.ChannelPermission config = config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).FirstOrDefault(); if (config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).ToList().Count == 0) { config = new ServerConfig.ChannelPermission(u.Channel.Id); config1.channelPerms.Add(config); } ServerConfig.CommandPermission commandperm; if (config.commandPerms.Where(i => i.Command == u.GetArg("Command")).ToList().Count > 0) { commandperm = config.commandPerms.Where(i => i.Command == u.GetArg("Command")).FirstOrDefault(); config.commandPerms.Remove(commandperm); } else { await u.Channel.SendMessage("Permissions UnSucksecksful"); } config1.channelPerms[config1.channelPerms.FindIndex(y => y.ChannelID == u.Channel.Id)] = config; ServerConfig.WriteServerConfig(config1); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("role").Description("Sets Permission Level for Role (has to be EXACT name of role)").Parameter("Command").Parameter("Level").Do(async u => { ServerConfig config1 = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.ChannelPermission config = config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).FirstOrDefault(); if (config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).ToList().Count == 0) { config = new ServerConfig.ChannelPermission(u.Channel.Id); config1.channelPerms.Add(config); } ServerConfig.RolePermission commandperm; if (config.rolePerms.Where(i => i.Role == u.GetArg("Command")).ToList().Count > 0) { commandperm = config.rolePerms.Where(i => i.Role == u.GetArg("Command")).FirstOrDefault(); commandperm.Level = Int32.Parse(u.GetArg("Level")); config.rolePerms[config.rolePerms.IndexOf(config.rolePerms.Where(i => i.Role == u.GetArg("Command")).FirstOrDefault())] = commandperm; } else { config.rolePerms.Add(new ServerConfig.RolePermission(u.GetArg("Command"), Int32.Parse(u.GetArg("Level")))); } config1.channelPerms[config1.channelPerms.FindIndex(y => y.ChannelID == u.Channel.Id)] = config; ServerConfig.WriteServerConfig(config1); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("removerole").Description("Removes Permission Level for Role (has to be EXACT name of role)").Parameter("Command").Do(async u => { ServerConfig config1 = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.ChannelPermission config = config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).FirstOrDefault(); if (config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).ToList().Count == 0) { config = new ServerConfig.ChannelPermission(u.Channel.Id); config1.channelPerms.Add(config); } ServerConfig.RolePermission commandperm; if (config.rolePerms.Where(i => i.Role == u.GetArg("Command")).ToList().Count > 0) { commandperm = config.rolePerms.Where(i => i.Role == u.GetArg("Command")).FirstOrDefault(); config.rolePerms.Remove(commandperm); } else { await u.Channel.SendMessage("Permissions UnSucksecksful"); } config1.channelPerms[config1.channelPerms.FindIndex(y => y.ChannelID == u.Channel.Id)] = config; ServerConfig.WriteServerConfig(config1); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("user").Description("Sets Permission Level for User (has to be mention)").Parameter("Command").Parameter("Level").Do(async u => { List<char> input = u.GetArg("Command").ToCharArray().ToList(); input.RemoveAt(0); input.RemoveAt(0); input.RemoveAt(input.Count - 1); ulong id = ulong.Parse(String.Concat(input)); ServerConfig config1 = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.ChannelPermission config = config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).FirstOrDefault(); if (config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).ToList().Count == 0) { config = new ServerConfig.ChannelPermission(u.Channel.Id); config1.channelPerms.Add(config); } ServerConfig.UserPermission commandperm; if (config.userPerms.Where(i => i.UserID == id).ToList().Count > 0) { commandperm = config.userPerms.Where(i => i.UserID == id).FirstOrDefault(); commandperm.Level = Int32.Parse(u.GetArg("Level")); config.userPerms[config.userPerms.IndexOf(config.userPerms.Where(i => i.UserID == id).FirstOrDefault())] = commandperm; } else { config.userPerms.Add(new ServerConfig.UserPermission(id, Int32.Parse(u.GetArg("Level")))); } config1.channelPerms[config1.channelPerms.FindIndex(y => y.ChannelID == u.Channel.Id)] = config; ServerConfig.WriteServerConfig(config1); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("removeuser").Description("Removes Permission Level for User (has to be mention)").Parameter("Command").Do(async u => { List<char> input = u.GetArg("Command").ToCharArray().ToList(); input.RemoveAt(0); input.RemoveAt(0); input.RemoveAt(input.Count - 1); ulong id = ulong.Parse(String.Concat(input)); ServerConfig config1 = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.ChannelPermission config = config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).FirstOrDefault(); if (config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).ToList().Count == 0) { config = new ServerConfig.ChannelPermission(u.Channel.Id); config1.channelPerms.Add(config); } ServerConfig.UserPermission commandperm; if (config.userPerms.Where(i => i.UserID == id).ToList().Count > 0) { commandperm = config.userPerms.Where(i => i.UserID == id).FirstOrDefault(); config.userPerms.Remove(commandperm); } else { await u.Channel.SendMessage("Permissions UnSucksecksful"); } config1.channelPerms[config1.channelPerms.FindIndex(y => y.ChannelID == u.Channel.Id)] = config; ServerConfig.WriteServerConfig(config1); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("commanduser").Description("Blacklists/Whitelists commands for certain user").Parameter("User").Parameter("Command").Parameter("Enabled").Do(async u => { List<char> input = u.GetArg("User").ToCharArray().ToList(); input.RemoveAt(0); input.RemoveAt(0); input.RemoveAt(input.Count - 1); ulong id = ulong.Parse(String.Concat(input)); ServerConfig config1 = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.ChannelPermission config = config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).FirstOrDefault(); if (config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).ToList().Count == 0) { config = new ServerConfig.ChannelPermission(u.Channel.Id); config1.channelPerms.Add(config); } ServerConfig.UserCommandPermission commandperm; if (config.userCommandPerms.Where(i => (i.Command == u.GetArg("Command") && i.UserID == id)).ToList().Count > 0) { commandperm = config.userCommandPerms.Where(i => i.Command == u.GetArg("Command") && i.UserID == id).FirstOrDefault(); commandperm.UserID = id; commandperm.enabled = bool.Parse(u.GetArg("Enabled")); config.userCommandPerms[config.userCommandPerms.IndexOf(config.userCommandPerms.Where(i => i.Command == u.GetArg("Command") && i.UserID == id).FirstOrDefault())] = commandperm; } else { config.userCommandPerms.Add(new ServerConfig.UserCommandPermission(id, u.GetArg("Command"), bool.Parse(u.GetArg("Enabled")))); } config1.channelPerms[config1.channelPerms.FindIndex(y => y.ChannelID == u.Channel.Id)] = config; ServerConfig.WriteServerConfig(config1); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("removecommanduser").Description("Removes a Blacklist/Whitelist command for certain user").Parameter("User").Parameter("Command").Do(async u => { List<char> input = u.GetArg("User").ToCharArray().ToList(); input.RemoveAt(0); input.RemoveAt(0); input.RemoveAt(input.Count - 1); ulong id = ulong.Parse(String.Concat(input)); ServerConfig config1 = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.ChannelPermission config = config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).FirstOrDefault(); if (config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).ToList().Count == 0) { config = new ServerConfig.ChannelPermission(u.Channel.Id); config1.channelPerms.Add(config); } ServerConfig.UserCommandPermission commandperm; if (config.userCommandPerms.Where(i => (i.Command == u.GetArg("Command") && i.UserID == id)).ToList().Count > 0) { commandperm = config.userCommandPerms.Where(i => i.Command == u.GetArg("Command") && i.UserID == id).FirstOrDefault(); config.userCommandPerms.Remove(commandperm); } else { await u.Channel.SendMessage("Permissions UnSucksecksful"); } config1.channelPerms[config1.channelPerms.FindIndex(y => y.ChannelID == u.Channel.Id)] = config; ServerConfig.WriteServerConfig(config1); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("commandrole").Description("Blacklists/Whitelists commands for certain role").Parameter("User").Parameter("Command").Parameter("Enabled").Do(async u => { // List<char> input = u.GetArg("User").ToCharArray().ToList(); // input.RemoveAt(0); // input.RemoveAt(0); // input.RemoveAt(input.Count - 1); // ulong id = ulong.Parse(String.Concat(input)); ServerConfig config1 = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.ChannelPermission config = config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).FirstOrDefault(); if(config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).ToList().Count == 0) { config = new ServerConfig.ChannelPermission(u.Channel.Id); config1.channelPerms.Add(config); } ServerConfig.RoleCommandPermission commandperm; if (config.roleCommandPerms.Where(i => (i.Command == u.GetArg("Command") && i.Role == u.GetArg("User"))).ToList().Count > 0) { commandperm = config.roleCommandPerms.Where(i => i.Command == u.GetArg("Command") && i.Role == u.GetArg("User")).FirstOrDefault(); commandperm.Role = u.GetArg("User"); commandperm.enabled = bool.Parse(u.GetArg("Enabled")); config.roleCommandPerms[config.roleCommandPerms.IndexOf(config.roleCommandPerms.Where(i => i.Command == u.GetArg("Command") && i.Role == u.GetArg("User")).FirstOrDefault())] = commandperm; } else { config.roleCommandPerms.Add(new ServerConfig.RoleCommandPermission(u.GetArg("User"), u.GetArg("Command"), bool.Parse(u.GetArg("Enabled")))); } config1.channelPerms[config1.channelPerms.FindIndex(y => y.ChannelID == u.Channel.Id)] = config; ServerConfig.WriteServerConfig(config1); await u.Channel.SendMessage("Permissions Sucksecksful"); }); t.CreateCommand("removecommandrole").Description("Removes a Blacklist/Whitelist command for certain role").Parameter("User").Parameter("Command").Do(async u => { // List<char> input = u.GetArg("User").ToCharArray().ToList(); // input.RemoveAt(0); // input.RemoveAt(0); // input.RemoveAt(input.Count - 1); // ulong id = ulong.Parse(String.Concat(input)); ServerConfig config1 = ServerConfig.GetServerConfig(u.Channel.Server.Id); ServerConfig.ChannelPermission config = config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).FirstOrDefault(); if (config1.channelPerms.Where(i => i.ChannelID == u.Channel.Id).ToList().Count == 0) { config = new ServerConfig.ChannelPermission(u.Channel.Id); config1.channelPerms.Add(config); } ServerConfig.RoleCommandPermission commandperm; if (config.roleCommandPerms.Where(i => (i.Command == u.GetArg("Command") && i.Role == u.GetArg("User"))).ToList().Count > 0) { commandperm = config.roleCommandPerms.Where(i => i.Command == u.GetArg("Command") && i.Role == u.GetArg("User")).FirstOrDefault(); config.roleCommandPerms.Remove(commandperm); } else { await u.Channel.SendMessage("Permissions UnSucksecksful"); } config1.channelPerms[config1.channelPerms.FindIndex(y => y.ChannelID == u.Channel.Id)] = config; ServerConfig.WriteServerConfig(config1); await u.Channel.SendMessage("Permissions Sucksecksful"); }); }); }); _client.ExecuteAndWait(async ()=>{ await _client.Connect("MTcxNzEyMTAwMzE2NjEwNTYx.CfbSCw.saNJTaBcw4EN8nZjjlzhzuHzJFI"); //"*****@*****.**", "mushroom12345" }); }
static void Main(string[] args) { if (!restart) { rpg = new KokoroBotRPG(); loadFiles(); } else { restart = false; } { DiscordClientConfig config = new DiscordClientConfig(); config.VoiceMode = DiscordVoiceMode.Outgoing; config.VoiceBufferLength = 40; var client = new DiscordClient(config); //Display all log messages in the console client.LogMessage += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}"); client.MessageReceived += async (s, e) => { Console.WriteLine(e.Message.User.Name + ": " + e.Message.Text); if (!e.Message.IsAuthor) { var currentChannel = e.Channel; if (e.User.Id == 95543627391959040) { if (e.Message.Text == "-mute") { mute = !mute; await client.SendMessage(currentChannel, "KokoroBot is now mute: " + mute.ToString()); } else if (e.Message.Text == "-clear") { if (voiceclient != null) voiceclient.ClearVoicePCM(); } else if (e.Message.Text == "-save") { saveFiles(); await client.SendMessage(currentChannel, "I have saved everything :3"); } else if (e.Message.Text == "-dc") { quit = true; running = false; } else if (e.Message.Text == "-restart") { await client.SendMessage(currentChannel, "Cya on the other side :3"); restart = true; running = false; await client.Disconnect(); } else if (e.Message.Text.StartsWith("-join")) { var channels = e.Server.Channels.Where((Channel chan) => { return e.Message.Text.Substring(5).TrimStart(' ') == chan.Name && chan.Type == ChannelType.Voice; }); if (channels.Any()) { var channel = channels.First(); Console.WriteLine("KokoroBot tries to join Channel: " + channel.Name); voiceclient = await client.JoinVoiceServer(channel); voiceserver = e.Message.Server; } } else if (e.Message.Text == "-leave") { if (voiceclient != null) { voiceclient.ClearVoicePCM(); await client.LeaveVoiceServer(voiceserver); voiceclient = null; voiceserver = null; } } } else if (e.User.Name == "part") { await client.SendMessage(currentChannel, "I don't like you. B-b-baka. >.<"); return; } if (!mute) { if (e.Message.Text.Length > 0) { string[] splitmessage = e.Message.Text.Split(' '); if (splitmessage[0] == "-kardfacts") { if (splitmessage.Length > 2) { if (splitmessage[1] == "add") { try { string finalstr = ""; for (int i = 2; i < splitmessage.Length; i++) { if (i != 2) finalstr += ' ' + splitmessage[i]; else finalstr = splitmessage[i]; } if (finalstr.Length > 5) { kardFactsStrings.Add(finalstr); await client.SendMessage(currentChannel, "A new fact about Kard has been added. (Yay ^-^):"); currentChannel = e.Channel; await client.SendMessage(currentChannel, finalstr); } else { throw new IOException("Hue."); } } catch (Exception) { await client.SendMessage(currentChannel, "That hurt <.< Don't do this again, ok? :3"); } } } else { await client.SendMessage(currentChannel, kardFacts()); } } else if (e.Message.Text.StartsWith("-play")) { Task.Run(() => { PlaySoundWav(e); }); } else if(e.Message.Text.StartsWith("-getclientid")) { if (e.Message.Text.Length > "-getclientid ".Length) { try { await client.SendMessage(currentChannel, e.Server.Members.Where((User u) => { return u.Name.StartsWith(e.Message.Text.Substring("-getclientid ".Length)); }).First().Id.ToString()); } catch(Exception) { await client.SendMessage(currentChannel, "User does not exist. B-baka."); } } else { await client.SendMessage(currentChannel, e.Message.User.Id.ToString()); } } else if(e.Message.Text.StartsWith(":")) { await rpg.HandleCommands(e, client, currentChannel); } else if (await handleSimpleCommands(e, client, currentChannel) == false) { await handleTiroCommands(e, client, currentChannel); } } } } }; //Convert our sync method to an async one and block the Main function until the bot disconnects client.Run(async () => { //Connect to the Discord server using our email and password await client.Connect(Sensitive.email, Sensitive.passwd); while (running) { var inputTask = Task.Run<string>((Func<string>)Console.ReadLine); await inputTask; string dbgCommand = inputTask.Result; if( dbgCommand == "exit" || restart || quit) { running = false; await client.Disconnect(); } else if ( dbgCommand == "listservers") { foreach(Server s in client.AllServers) { Console.WriteLine("#######################################"); Console.WriteLine("Servername: " + s.Name); Console.WriteLine("Voicechannels: "); foreach(Channel c in s.VoiceChannels) { Console.WriteLine(" "+c.Name); } Console.WriteLine("Channels: "); foreach (Channel c in s.Channels) { Console.WriteLine(" "+c.Name); } } } } //If we are not a member of any server, use our invite code (made beforehand in the official Discord Client) }); } if (!restart) { saveFiles(); } else { Main(new string[] { }); } }
public override void Stop() { Running = false; client.Disconnect(); }