public Command(VirtualServer _server, string _name, Action <ServerMessage, string> _cmd, PrivilegeLevel _priv, HelpMsgStrings _helpmessage) { server = _server; name = _name; helpmessage = _helpmessage; priv = _priv; cmd = _cmd; }
public AdminMessageChannel(VirtualServer _server) : base(_server) { var res = server.FileSetup(savefile); if (res.Count > 0) { channel = server.getServer().TextChannels.FirstOrDefault(x => x.Name == res[0]); } }
public EnableableCommandModule(VirtualServer _server, string _module_name) : base(_server) { module_name = _module_name; string statusString = String.Join("\n", server.FileSetup(module_name + filesuffix)); if (statusString == "on") { on = true; } }
public ReportModule(VirtualServer _server) : base(_server, "report") { ReportUsers = PersistantList.Create(server, "ReportUsers.txt"); BannedUsers = PersistantList.Create(server, "ReportBannedUsers.txt"); // Report channel to send reports to var res = server.FileSetup(_channelFile); if (res.Count > 0) { ReportChannel = server.getServer().TextChannels.FirstOrDefault(x => x.Name == res[0]); } }
public Adminleave(VirtualServer _server, AdminMessageChannel amc) : base(_server, "adminleave", new HelpMsgStrings("", "adminleave <on/off> <adminleave message>")) { if (amc == null || !amc.sameServer(this.server)) { throw new Exception("setup error"); } server.UserLeft += (s, u) => { if (on && amc.channel != null) { server.safeSendMessage(amc.channel, wmls.Response(u)); } }; }
public Admingreet(VirtualServer _server, AdminMessageChannel amc) : base(_server, "admingreet", new HelpMsgStrings("", "admingreet <on/off> <admingreet message>")) { if (amc == null || !amc.sameServer(this.server)) { throw new Exception("setup error"); } server.UserJoined += (s, u) => { if (on && u.Guild.Id == server.getServer().Id&& amc.channel != null) { server.safeSendMessage(amc.channel, wmls.Response(u)); } }; }
public GloriousDirectDemocracy(VirtualServer _server) : base(_server, "GloriousDirectDemocracy") { server.fileCommand(folder, x => System.IO.Directory.CreateDirectory(x)); List <string> arr = server.FileSetup(folder + LUIFileName); string LowestUnusedIdStr = "0"; if (arr.Count > 0) { LowestUnusedIdStr = arr[0]; } if (!ulong.TryParse(LowestUnusedIdStr, out lowestUnusedId)) { lowestUnusedId = 0; } NameOfAllProposals = server.XMlDictSetup <String, ulong>(folder + MasterTableFileName); List <String> currentProposals = server.FileSetup(folder + CurrentProposalNamesFileName); Proposals = new Dictionary <ulong, Proposal>(currentProposals.Count + 10); pastProposals = new Dictionary <ulong, LazyDiscLoaded <Proposal> >(); foreach (var entry in NameOfAllProposals) { string filename = folder + entry.Value + ".prop"; if (currentProposals.FindIndex(x => x == entry.Key) != -1) { //currentProposal try { /* string outPut = server.fileCommand(filename, x => System.IO.File.ReadAllText(x)); * var prop = //Proposal.FromString(outPut); */ var prop = server.fileCommand(filename, x => Funcs.XMLSetup <Proposal>(x)); Proposals.Add(entry.Value, prop); if (prop.Started) { queuePropEnd(prop, entry.Value); } } catch { Console.WriteLine("Unable to Get Proposal " + entry.Value + " - '" + entry.Key + "'"); } } else { //pastProposal pastProposals.Add(entry.Value, new LazyDiscLoaded <Proposal>(filename, y => server.fileCommand(y, x => Funcs.XMLSetup <Proposal>(x)))); } } }
public Move(VirtualServer _server) : base(_server) { var res = server.FileSetup(vSourceFile); if (res.Count > 0) { vSource = server.getServer().VoiceChannels.FirstOrDefault(x => x.Name == res[0]); } var res2 = server.FileSetup(vTargetFile); if (res2.Count > 0) { vTarget = server.getServer().VoiceChannels.FirstOrDefault(x => x.Name == res2[0]); } }
public LobbyGreet(VirtualServer _server) : base(_server, "lobbygreet", new HelpMsgStrings("", "lobbygreet <channel> <on/off> <lobbygreet message>")) { var res = server.FileSetup(savefile); if (res.Count > 0) { channel = server.getServer().TextChannels.FirstOrDefault(x => x.Name == res[0]); } server.UserJoined += (s, u) => { if (on && u.Guild.Id == server.getServer().Id&& channel != null) { server.safeSendMessage(channel, wmls.Response(u)); } }; }
public Autogreet(VirtualServer _server) : base(_server, "autogreet", new HelpMsgStrings("", "autogreet <on/off> <autogreet message>")) { server.UserJoined += async(s, u) => { if (on) { var x = await u.GetOrCreateDMChannelAsync(); var chn = x as SocketDMChannel; if (chn != null) { server.safeSendMessage(chn, wmls.Response(u)); } else { Console.WriteLine("Could not create DM channel with: " + u.Username); } } }; }
async public Task <bool> start(Action <Proposal> store, VirtualServer serv, ServerMessage msg, ulong propId) { if (Started) { return(false); } var ownMsg = await serv.safeSendMessage(msg.Channel, PropPrint(false, propId)); if (ownMsg == null) { return(false); } Started = true; msgId = ownMsg.Id; channelId = ownMsg.Channel.Id; this.TimeOfCompletion = DateTime.Now + this.TotalDuration; store(this); return(true); }
/// <summary> /// Default constructor /// Initializes the whitelisted roles from the file /// </summary> /// <param name="_server"></param> public RoleCommand(VirtualServer _server, LobbyGreet _lg) : base(_server, "role") { WhitelistedRoles = PersistantList.Create(server, "WhitelistedRoles.txt"); server.RoleUpdated += (s, tup) => roleUpdated(tup.Item1, tup.Item2); server.RoleDeleted += (s, r) => roleDeleted(r); // Get the strike channel to print admin alerts in var res = server.FileSetup(_timeoutFile); if (res.Count > 0) { TimeoutRole = server.getServer().Roles.FirstOrDefault(x => x.Name == res[0]); } lg = _lg; if (lg != null) { string statusString = String.Join("\n", server.FileSetup("lobbyselfserviceenableStatus.txt")); if (statusString == "off") { lssOn = false; } } }
/// <summary> /// Default constructor /// </summary> /// <param name="_server"></param> public StrikeModule(VirtualServer _server) : base(_server, "strike") { UserStrikes = PersistantDict <ulong, List <StrikeDetails> > .load(_server, "UserStrikes.xml"); // Get the strike channel to print admin alerts in var res = server.FileSetup(_channelFile); if (res.Count > 0) { StrikeChannel = server.getServer().TextChannels.FirstOrDefault(x => x.Name == res[0]); } var time = server.FileSetup(daysTillAutoresolveFile); if (time.Count == 1 && UInt32.TryParse(time[0], out daysTillAutoresolve)) { cleanupStrikes(); } else { daysTillAutoresolve = 0; } }
public WelcomeMessageCommandHandler(VirtualServer _server, string _command, HelpMsgStrings _helpmsgstring) : base(_server) { command = _command; helpmsgstring = _helpmsgstring; string message = String.Join("\n", server.FileSetup(command + ".txt")); if (message == String.Empty) { wmls = new WelcomeMessage("Welcome " + WelcomeMessageId.raw); } else { var split = message.Split("\n".ToArray(), 2); if (split.Length == 2) { if (split[0] == "on") { on = true; } else if (split[0] == "off") { on = false; } else { Console.WriteLine("Welcome message in corrupted format: " + message); } wmls = new WelcomeMessage(split[1]); } else { wmls = new WelcomeMessage("Welcome " + WelcomeMessageId.raw); } } }
public bool sameServer(VirtualServer vs) { return(vs == server); }
internal static PersistantList Create(VirtualServer server, string filename) { var content = server.FileSetup(filename); return(new PersistantList(content, filename, server)); }
public PersistantList(List <String> content, string filename, VirtualServer server) { this.content = content; this.filename = filename; this.server = server; }
public static PersistantDict <T, K> load(VirtualServer _server, String _filename) { var x = _server.XMlDictSetup <T, K>(_filename); return(new PersistantDict <T, K>(_server, _filename, x)); }
private PersistantDict(VirtualServer _server, String _filename, Dictionary <T, K> d) : base(d) { server = _server; filename = _filename; }
public static Command AdminCommand(VirtualServer _server, string _name, Action <ServerMessage, String> _cmd, HelpMsgStrings _helpmessage) { return(new Command(_server, _name, _cmd, PrivilegeLevel.BotAdmin, _helpmessage)); }
public Bork(VirtualServer _server) : base(_server) { String str = String.Join("\n", server.FileSetup(borkFrequencyPath)); if (!Int32.TryParse(str, out frequency)) { frequency = 1; } if (frequency < 1) { frequency = 1; } borklist = server.XMlDictSetup <ulong, List <String> >(borklistPath); server.MessageRecieved += (s, e) => { List <String> localborklist; if (borklist.TryGetValue(e.Author.Id, out localborklist)) { ObjWrapper <int> count; if (!lastBorks.TryGetValue(e.Author.Id, out count)) { count = new ObjWrapper <int>(frequency); lastBorks.Add(e.Author.Id, count); } count.Item1 = count.Item1 + 1; if (count.Item1 >= frequency) { foreach (var y in localborklist) { // try // { //Todo: Rewrite this so that non-server emotes work as well! // IEmote emote = server.getServer().Emotes.Where(x => x.ToString() == "<"+y+">").FirstOrDefault(); Emote emote; if (Emote.TryParse(y, out emote) && server.getServer().Emotes.Select(em => em.Id).Contains(emote.Id)) { e.msg.AddReactionAsync(emote); } else { //todo: figure out how to remove an emoji after adding it failed? e.msg.AddReactionAsync(new Emoji(y)); } /* else * { * Console.WriteLine("could not find emote: " + y); * }*/ //bit of a hack to send a special msg /* var x = server.getServer().Client.ClientAPI.Send(new EmojiAddRequest(e.Channel.Id, e.Message.Id, y)); * x.Wait(); */ /* } * catch (Exception exception) * { * Console.WriteLine(exception); * }*/ } count.Item1 = 0; } } }; }
public AlternativeCommand(VirtualServer _server) : base(_server, "altcommand") { }
public Dice(VirtualServer _server) : base(_server, "roll") { rnd = new Random(); }
/// <summary> /// Default constructor /// </summary> /// <param name="_server"></param> public EmoteModule(VirtualServer _server) : base(_server, "emote") { Emotes = PersistantDict <ulong, EmoteStats> .load(_server, "EmoteStats.xml"); // Get the last reset date var res = server.FileSetup(_resetDateFile); if (res.Count > 0) { LastResetDate = res[0]; } else { _lastResetDate = new DateTimeOffset(DateTime.Now).ToString(); server.fileCommand(_resetDateFile, x => System.IO.File.WriteAllText(x, LastResetDate)); } Action <Emote> f = (emote) => { // Create a new entry if it doesn't have one if (!Emotes.ContainsKey(emote.Id)) { Emotes.Add(emote.Id, new EmoteStats() { Counter = 0, LastPosted = new DateTimeOffset(DateTime.Now).ToString(), Name = emote.Name }); } // Increment the counter Emotes[emote.Id].Counter++; Emotes[emote.Id].LastPosted = new DateTimeOffset(DateTime.Now).ToString(); Emotes.persist(); }; // Listen to all incoming messages from the server server.MessageRecieved += (s, e) => { if (!on) { return; } List <Emote> usedEmotes = new List <Emote>(); if (!e.Author.IsBot && e.msg.Tags.Any((t) => t.Type == TagType.Emoji && server.getServer().Emotes.Contains(t.Value))) { lock (_lock) { // Go over all the server emotes that weren't already posted foreach (var tag in e.msg.Tags.Where(t => t.Type == TagType.Emoji && server.getServer().Emotes.Contains(t.Value) && !usedEmotes.Contains(t.Value))) { // Add it to the previously posted list Emote emote = tag.Value as Emote; usedEmotes.Add(emote); if (emote != null) { f(emote); } } } } }; // Count for reactions server.ReactionAdded += (s, reaction) => { if (!on) { return; } // If a real user reacted wit ha server emote if (!reaction.User.Value.IsBot && server.getServer().Emotes.Contains(reaction.Emote)) { Emote emote = reaction.Emote as Emote; if (emote != null) { lock (_lock) { f(emote); } } } }; server.ReactionRemoved += (s, reaction) => { if (!on) { return; } // If a real user removed their server emote reaction if (!reaction.User.Value.IsBot && server.getServer().Emotes.Contains(reaction.Emote)) { Emote emote = reaction.Emote as Emote; if (emote != null) { lock (_lock) { // Decrement the counter if (Emotes.ContainsKey(emote.Id)) { Emotes[emote.Id].Counter--; Emotes.persist(); } } } } }; }
public Math(VirtualServer _server) : base(_server, "math") { }
public Reminder(VirtualServer _server) : base(_server) { }
public CommandHandler(VirtualServer _server) { server = _server; }
public KillUserMessages(VirtualServer _server) : base(_server, "killmessages") { }
public PurgeTheEnclave(VirtualServer _server) : base(_server, "enclavepurge") { try { var chan = server.FileSetup(adminChan); if (chan.Count > 0) { channel = server.getServer().TextChannels.FirstOrDefault(x => x.Name == chan[0]); } var str = server.FileSetup(enclaveRoleFile); ulong roleId; if (str.Count > 0) { if (UInt64.TryParse(str[0], out roleId)) { role = server.getServer().Roles.FirstOrDefault(x => x.Id == roleId); } } watchlist = server.XMlDictSetup <ulong, DateTime>(watchlistPath); watchlist.ToList().Select(x => { Console.WriteLine("Watchlist element"); TimeSpan y = DateTime.Now.Subtract(x.Value.Add(span)); var res = y.TotalMilliseconds; if (res <= 0) { sendMessage(null, x.Key); } else { var z = new Timer(res); z.Elapsed += (s, e) => sendMessage((Timer)s, x.Key); z.Start(); } return(0); }); server.UserUpdated += (o, e) => { var before = e.Item1; var after = e.Item2; if (role != null) { try { bool wasEnclave = before.Roles.Contains(role); bool isEnclave = after.Roles.Contains(role); if (wasEnclave && !isEnclave && watchlist.ContainsKey(after.Id)) { Console.WriteLine("no more Enclave for: " + after.Username); watchlist.Remove(after.Id); } else if (!wasEnclave && isEnclave && !watchlist.ContainsKey(after.Id)) { Console.WriteLine("now Enclave: " + after.Username); watchlist.Add(after.Id, DateTime.Now); var z = new Timer(span.TotalMilliseconds); z.Elapsed += (s, e2) => sendMessage((Timer)s, after.Id); z.Start(); } } catch (Exception excep) { Console.WriteLine(excep); } } }; server.UserLeft += (o, e) => { if (watchlist.ContainsKey(e.Id)) { watchlist.Remove(e.Id); } }; } catch (Exception excep) { Console.WriteLine(excep); } }
public Userinfo(VirtualServer _server) : base(_server) { }