bool cmdDeleteFact(VPServices app, Avatar who, string data) { var fact = getFact(data); if (fact == null) { app.Warn(who.Session, msgNonExistant); return(true); } // Only allow deletion of locked factoid if owner or bot owner if (fact.Locked && !who.Name.IEquals(app.Owner)) { if (fact.WhoID != who.Id) { app.Warn(who.Session, msgLocked, fact.WhoID); return(true); } } lock (app.DataMutex) connection.Execute("DELETE FROM Facts WHERE Topic = ? COLLATE NOCASE", data); app.Notify(who.Session, msgDeleted); return(Log.Info(Name, "{0} deleted factoid for topic {1}", who.Name, data)); }
bool cmdDelJump(VPServices app, Avatar who, string data) { var jumpsUrl = app.PublicUrl + webJumps; var name = data.ToLower(); // Reject null entries and reserved words if (name == "") { return(false); } else if (name == "random") { app.Warn(who.Session, msgReserved); return(true); } var jump = getJump(name); if (jump == null) { app.Warn(who.Session, msgNonExistant, jumpsUrl); return(Log.Debug(Name, "{1} tried to delete non-existant jump {0}", name, who.Name)); } else { lock (app.DataMutex) connection.Delete(jump); } app.NotifyAll(msgDeleted, name); return(Log.Info(Name, "Deleted {0} jump for {1}", name, who.Name)); }
bool cmdRKill(VPServices app, Avatar who, string data) { if (data != app.Bot.Name) { return(true); } if (!config.GetBoolean("Enabled", false)) { app.Warn(who.Session, msgDisabled); return(true); } var permitted = config.Get("Users", ""); if (!TRegex.IsMatch(who.Name, permitted)) { app.Warn(who.Session, msgUnauth); return(true); } // Perform the kill System.Environment.Exit(0); return(true); }
bool cmdGetFact(VPServices app, Avatar who, string data) { var fact = getFact(data); // Undefined topics if (fact == null) { app.Warn(who.Session, msgNonExistant); return(true); } // Alias topics if (fact.Description.StartsWith("@")) { var aliasTopic = fact.Description.Substring(1); var alias = getFact(aliasTopic); if (alias == null) { app.Warn(who.Session, msgBrokenAlias, aliasTopic, data); return(true); } app.NotifyAll(msgFact, alias.Topic, alias.Description); return(true); } app.NotifyAll(msgFact, fact.Topic, fact.Description); return(true); }
bool cmdDeleteTodo(VPServices app, Avatar who, string data) { var ids = data.TerseSplit(","); foreach (var entry in ids) { var trimmed = entry.Trim(); int id; if (!int.TryParse(trimmed, out id)) { app.Warn(who.Session, msgInvalid, trimmed); continue; } lock (app.DataMutex) { var affected = connection.Execute("DELETE FROM Todo WHERE ID = ?", id); if (affected <= 0) { app.Warn(who.Session, msgNonExistant, id); } else { Log.Info(Name, "Deleted todo #{0} for {1}", id, who.Name); } } } app.Notify(who.Session, msgDeleted); return(true); }
bool onRequest(VPServices app, Avatar source, string targetName, bool invite) { // Ignore if self if (source.Name.IEquals(targetName)) { app.Warn(source.Session, msgSelf); return(true); } // Reject if source has request if (!isRequestee(source.Session).Equals(JoinInvite.Nobody)) { app.Warn(source.Session, msgPendingRequester); return(Log.Info(Name, "Rejecting request by {0} as they already have one pending", source)); } // Reject if target has request if (!isRequested(targetName).Equals(JoinInvite.Nobody)) { app.Warn(source.Session, msgPendingRequestee); return(Log.Info(Name, "Rejecting request by {0} as they already have one pending", source)); } // Ignore if no such users found var action = invite ? "invite" : "join"; var targets = app.GetUsers(targetName); if (targets.Length <= 0) { app.Warn(source.Session, msgNotPresent); return(true); } // Request all sessions of given name foreach (var target in targets) { app.Notify(target.Session, msgRequest, source.Name, action); } app.Notify(source.Session, msgRequestSent, targetName); requests.Add(new JoinInvite { By = source.Session, Who = targetName.ToLower(), When = DateTime.Now, Invite = invite }); return(true); }
bool cmdMute(VPServices app, Avatar who, string target, bool muting) { // Mute IRC if (target == "") { who.SetSetting(settingMuteIRC, muting); app.Notify(who.Session, msgMuteIRC, muting ? "hidden from" : "shown to"); return(true); } // Reject invalid names if (target.Contains(',')) { app.Warn(who.Session, "Cannot mute that name; commas not allowed"); return(true); } var muteList = who.GetSetting(settingMuteList); var muted = (muteList ?? "").TerseSplit(',').ToList(); target = target.ToLower(); if (muting) { if (muted.Contains(target)) { app.Warn(who.Session, msgMuted, "already"); return(true); } muted.Add(target); app.Notify(who.Session, msgMuteUser, target, "hidden"); } else { if (!muted.Contains(target)) { app.Warn(who.Session, msgMuted, "not"); return(true); } muted.Remove(target); app.Notify(who.Session, msgMuteUser, target, "shown"); } muteList = string.Join(",", muted); who.SetSetting(settingMuteList, muteList); return(true); }
bool cmdMute(VPServices app, Avatar who, string target, bool muting) { // Mute IRC if (target == "") { who.SetSetting(settingMuteIRC, muting); app.Notify(who.Session, msgMuteIRC, muting ? "hidden from" : "shown to"); return true; } // Reject invalid names if ( target.Contains(',') ) { app.Warn(who.Session, "Cannot mute that name; commas not allowed"); return true; } var muteList = who.GetSetting(settingMuteList); var muted = ( muteList ?? "" ).TerseSplit(',').ToList(); target = target.ToLower(); if (muting) { if ( muted.Contains(target) ) { app.Warn(who.Session, msgMuted, "already"); return true; } muted.Add(target); app.Notify(who.Session, msgMuteUser, target, "hidden"); } else { if ( !muted.Contains(target) ) { app.Warn(who.Session, msgMuted, "not"); return true; } muted.Remove(target); app.Notify(who.Session, msgMuteUser, target, "shown"); } muteList = string.Join(",", muted); who.SetSetting(settingMuteList, muteList); return true; }
bool cmdJump(VPServices app, Avatar who, string data) { var jumpsUrl = app.PublicUrl + webJumps; var name = data.ToLower(); // Reject null if (name == "") { return(false); } lock (app.DataMutex) { var jump = (name == "random") ? connection.Query <sqlJump>("SELECT * FROM Jumps ORDER BY RANDOM() LIMIT 1;").FirstOrDefault() : getJump(name); if (jump != null) { app.Bot.Avatars.Teleport(who.Session, "", new Vector3(jump.X, jump.Y, jump.Z), jump.Yaw, jump.Pitch); } else { app.Warn(who.Session, msgNonExistant, jumpsUrl); } } return(true); }
bool cmdBeginTrivia(VPServices app, Avatar who, string data) { if (entries == null) { app.Notify(who.Session, msgFirstLoad); Log.Debug(tag, msgFirstLoad); if (!loadTrivia()) { app.Bot.Say("Sorry, I was unable to start trivia as my database is missing"); return(true); } } // Skip question if (inProgress) { app.Notify(who.Session, msgSkipping); Log.Debug(tag, msgSkipping); skipQuestion(); } var entry = fetchEntry(data); if (entry == null) { app.Warn(who.Session, msgNoResults); } else { gameBegin(entry); } return(true); }
bool cmdJumpList(VPServices app, Avatar who, string data) { var jumpsUrl = app.PublicUrl + webJumps; // No search; list URL only if (data == "") { app.Notify(who.Session, jumpsUrl); return(true); } lock (app.DataMutex) { var query = from j in connection.Table <sqlJump>() where j.Name.Contains(data) select j; // No results if (query.Count() <= 0) { app.Warn(who.Session, msgNoResults, jumpsUrl); return(true); } // Iterate results app.Bot.ConsoleMessage(who.Session, ChatEffect.BoldItalic, VPServices.ColorInfo, "", msgResults, data); foreach (var q in query) { app.Bot.ConsoleMessage(who.Session, ChatEffect.Italic, VPServices.ColorInfo, "", msgResult, q.Name, q.Creator, q.When); } } return(true); }
bool cmdBeginTrivia(VPServices app, Avatar who, string data) { if ( entries == null ) { app.Notify(who.Session, msgFirstLoad); Log.Debug(tag, msgFirstLoad); if ( !loadTrivia() ) { app.Bot.Say("Sorry, I was unable to start trivia as my database is missing"); return true; } } // Skip question if ( inProgress ) { app.Notify(who.Session, msgSkipping); Log.Debug(tag, msgSkipping); skipQuestion(); } var entry = fetchEntry(data); if (entry == null) app.Warn(who.Session, msgNoResults); else gameBegin(entry); return true; }
bool cmdHelp(VPServices app, Avatar who, string data) { var helpUrl = app.PublicUrl + "help"; if (data != "") { // If given data, try to find specific command and print help in console for // that user foreach (var cmd in app.Commands) { if (TRegex.IsMatch(data, cmd.Regex)) { app.Bot.ConsoleMessage(who.Session, ChatEffect.BoldItalic, VPServices.ColorInfo, "", msgCommandTitle, cmd.Name); app.Bot.ConsoleMessage(who.Session, ChatEffect.Italic, VPServices.ColorInfo, "", msgCommandRgx, cmd.Regex); app.Bot.ConsoleMessage(who.Session, ChatEffect.Italic, VPServices.ColorInfo, "", msgCommandDesc, cmd.Help); app.Bot.ConsoleMessage(who.Session, ChatEffect.Italic, VPServices.ColorInfo, "", msgCommandExample, cmd.Example); return(true); } } app.Warn(who.Session, "Could not match any command for '{0}'; try {1}", data, helpUrl); return(true); } else { // Broadcast help URL for everybody app.NotifyAll("Command help can be found at {0}", helpUrl); return(true); } }
bool cmdReadTelegrams(VPServices app, Avatar who, string data) { var grams = getUnread(who.Name); if (grams.Count() <= 0) { app.Warn(who.Session, msgNoTelegrams); return(true); } lock (app.DataMutex) { connection.BeginTransaction(); foreach (var gram in grams) { app.Bot.ConsoleMessage(who.Session, ChatEffect.Bold, VPServices.ColorAlert, "", msgTelegram, gram.Source, gram.When); app.Bot.ConsoleMessage(who.Session, ChatEffect.None, VPServices.ColorAlert, "", gram.Message); app.Bot.ConsoleMessage(who.Session, ChatEffect.None, VPServices.ColorAlert, "", ""); gram.Read = true; connection.Update(gram); } connection.Commit(); } return(true); }
void onEnter(Instance sender, Avatar user) { if (user.GetSettingBool(keyMode)) { app.Warn(user.Session, msgReminder); } }
bool cmdBeginTrivia(VPServices app, Avatar who, string data) { if ( entries == null ) { app.Notify(who.Session, msgFirstLoad); Log.Debug(tag, msgFirstLoad); loadTrivia(); } // Skip question if ( inProgress ) { app.Notify(who.Session, msgSkipping); Log.Debug(tag, msgSkipping); skipQuestion(); } var entry = fetchEntry(data); if (entry == null) app.Warn(who.Session, msgNoResults); else gameBegin(entry); return true; }
bool onResponse(VPServices app, Avatar targetAv, bool yes) { var sourceReq = isRequested(targetAv.Name); // Reject non-requested if (sourceReq.Equals(JoinInvite.Nobody)) { app.Warn(targetAv.Session, msgNoRequests); return(true); } requests.Remove(sourceReq); // Rejected requests if (!yes) { app.Notify(sourceReq.By, msgRequestRejected); return(true); } var target = app.GetUser(targetAv.Session); var source = app.GetUser(sourceReq.By); // Reject phantom users if (target == null) { return(true); } // Reject if source has gone away if (source == null) { app.Warn(targetAv.Session, msgNotPresent); return(Log.Info(Name, "Rejecting response by {0} as they have left", source.Name)); } var targetPos = sourceReq.Invite ? source.Position : target.Position; var targetSession = sourceReq.Invite ? target.Session : source.Session; var targetMsg = sourceReq.Invite ? msgInvited : msgJoined; app.Notify(target.Session, targetMsg, source.Name); app.Bot.Avatars.Teleport(targetSession, "", new Vector3(targetPos.X, targetPos.Y, targetPos.Z), 0, 0); return(true); }
bool cmdRKill(VPServices app, Avatar who, string data) { if (data != app.Bot.Name) return true; if ( !config.GetBoolean("Enabled", false) ) { app.Warn(who.Session, msgDisabled); return true; } var permitted = config.Get("Users", ""); if ( !TRegex.IsMatch(who.Name, permitted) ) { app.Warn(who.Session, msgUnauth); return true; } // Perform the kill System.Environment.Exit(0); return true; }
bool cmdIRCDisconnect(VPServices app, Avatar who, string data) { lock (mutex) { if (!irc.IsConnected) { app.Warn(who.Session, msgNotConnected); return(true); } disconnect(app); return(true); } }
bool cmdIRCConnect(VPServices app, Avatar who, string data) { lock (mutex) { if (irc.IsConnected) { app.Warn(who.Session, msgAlreadyConnected, config.Channel, config.Host); return(true); } connect(app); return(true); } }
bool cmdIRCConnect(VPServices app, Avatar who, string data) { lock (mutex) { if (irc.IsConnected) { app.Warn(who.Session, msgAlreadyConnected, config.Channel, config.Host); return true; } connect(app); return true; } }
bool cmdIRCDisconnect(VPServices app, Avatar who, string data) { lock (mutex) { if (!irc.IsConnected) { app.Warn(who.Session, msgNotConnected); return true; } disconnect(app); return true; } }
bool cmdAddJump(VPServices app, Avatar who, string data) { var name = data.ToLower(); // Reject null entries and reserved words if (name == "") { return(false); } else if (name == "random") { app.Warn(who.Session, msgReserved); return(true); } if (getJump(name) != null) { app.Warn(who.Session, msgExists); return(Log.Debug(Name, "{0} tried to overwrite jump {1}", who.Name, getJump(name).Name)); } lock (app.DataMutex) connection.Insert(new sqlJump { Name = name, Creator = who.Name, When = DateTime.Now, X = who.X, Y = who.Y, Z = who.Z, Pitch = who.Pitch, Yaw = who.Yaw }); app.NotifyAll(msgAdded, name, who.X, who.Y, who.Z, who.Yaw, who.Pitch); return(Log.Info(Name, "Saved a jump for {0} at {1}, {2}, {3} for {4}", who.Name, who.X, who.Y, who.Z, name)); }
bool cmdGetTodo(VPServices app, Avatar who, string data) { lock (app.DataMutex) { var random = connection.Query <sqlTodo>("SELECT * FROM Todo WHERE Done = ? ORDER BY RANDOM() LIMIT 1;", false).FirstOrDefault(); if (random == null) { app.Warn(who.Session, msgNoUndone); } else { app.Notify(who.Session, msgRandom, random.ID, random.Who, random.When); app.Notify(who.Session, "{0}", random.What); } return(true); } }
bool cmdAddFact(VPServices app, Avatar who, string data) { var matches = Regex.Match(data, "^(-+lock )?(.+?): (.+)$"); if (!matches.Success) { return(false); } var parts = matches.ToArray(); var locked = parts[1] != ""; var topic = parts[2].Trim(); var what = parts[3].Trim(); var old = getFact(topic); var msg = old == null ? msgAdded : msgOverwritten; // Only allow overwrite of locked previous factoid if owner or bot owner if (old != null && old.Locked && !who.Name.IEquals(app.Owner)) { if (old.WhoID != who.Id) { app.Warn(who.Session, msgLocked, old.WhoID); return(true); } } lock (app.DataMutex) { connection.Execute("DELETE FROM Facts WHERE Topic = ? COLLATE NOCASE", topic); connection.Insert(new sqlFact { Topic = topic, Description = what, When = DateTime.Now, WhoID = who.Id, Locked = locked }); } app.Notify(who.Session, msg, topic, locked ? "locked " : ""); return(Log.Info(Name, "Saved a fact from {0} for topic {1} (locked: {2})", who.Name, topic, locked)); }
bool cmdListTodo(VPServices app, Avatar who, string data) { var todoUrl = app.PublicUrl + webTodo; // No search; list URL only if (data == "") { app.Notify(who.Session, todoUrl); return(true); } lock (app.DataMutex) { var query = from t in connection.Table <sqlTodo>() where t.What.Contains(data) || t.Who.Contains(data) orderby t.Done ascending orderby t.ID descending select t; // No results if (query.Count() <= 0) { app.Warn(who.Session, msgNoResults, todoUrl); return(true); } // Iterate results app.Bot.ConsoleMessage(who.Session, ChatEffect.BoldItalic, VPServices.ColorInfo, "", msgResults, data); foreach (var q in query) { var done = q.Done ? '✓' : '✗'; var color = q.Done ? VPServices.ColorLesser : VPServices.ColorInfo; app.Bot.ConsoleMessage(who.Session, "", ""); app.Bot.ConsoleMessage(who.Session, ChatEffect.Italic, color, "", msgResultA, done, q.ID, q.What); app.Bot.ConsoleMessage(who.Session, ChatEffect.Italic, color, "", msgResultB, q.Who, q.When); } } return(true); }
bool cmdTogglePVP(VPServices app, Avatar who, string data) { var lastSwitch = who.GetSettingDateTime(keyLastSwitch); bool toggle = false; // Reject if too soon if (lastSwitch.SecondsToNow() < 60) { var timeLeft = 60 - lastSwitch.SecondsToNow(); app.Warn(who.Session, msgTooSoon, timeLeft); return(true); } if (data != "") { // Try to parse user given boolean; silently ignore on failure if (!VPServices.TryParseBool(data, out toggle)) { return(false); } } else { toggle = !who.GetSettingBool(keyMode); } // Set new boolean, timeout and if new, health who.SetSetting(keyMode, toggle); who.SetSetting(keyLastSwitch, DateTime.Now); initialHealth(who); var verb = toggle ? "enabled" : "disabled"; app.NotifyAll(msgToggle, verb, who.Name); return(true); }
bool cmdGetTodo(VPServices app, Avatar who, string data) { lock ( app.DataMutex ) { var random = connection.Query<sqlTodo>("SELECT * FROM Todo WHERE Done = ? ORDER BY RANDOM() LIMIT 1;", false).FirstOrDefault(); if ( random == null ) app.Warn(who.Session, msgNoUndone); else { app.Notify(who.Session, msgRandom, random.ID, random.Who, random.When); app.Notify(who.Session, "{0}", random.What); } return true; } }
bool cmdListTodo(VPServices app, Avatar who, string data) { var todoUrl = app.PublicUrl + webTodo; // No search; list URL only if ( data == "" ) { app.Notify(who.Session, todoUrl); return true; } lock ( app.DataMutex ) { var query = from t in connection.Table<sqlTodo>() where t.What.Contains(data) || t.Who.Contains(data) orderby t.Done ascending orderby t.ID descending select t; // No results if ( query.Count() <= 0 ) { app.Warn(who.Session, msgNoResults, todoUrl); return true; } // Iterate results app.Bot.ConsoleMessage(who.Session, ChatEffect.BoldItalic, VPServices.ColorInfo, "", msgResults, data); foreach ( var q in query ) { var done = q.Done ? '✓' : '✗'; var color = q.Done ? VPServices.ColorLesser : VPServices.ColorInfo; app.Bot.ConsoleMessage(who.Session, "", ""); app.Bot.ConsoleMessage(who.Session, ChatEffect.Italic, color, "", msgResultA, done, q.ID, q.What); app.Bot.ConsoleMessage(who.Session, ChatEffect.Italic, color, "", msgResultB, q.Who, q.When); } } return true; }
bool cmdDelJump(VPServices app, Avatar who, string data) { var jumpsUrl = app.PublicUrl + webJumps; var name = data.ToLower(); // Reject null entries and reserved words if ( name == "" ) return false; else if ( name == "random" ) { app.Warn(who.Session, msgReserved); return true; } var jump = getJump(name); if ( jump == null ) { app.Warn(who.Session, msgNonExistant, jumpsUrl); return Log.Debug(Name, "{1} tried to delete non-existant jump {0}", name, who.Name); } else lock (app.DataMutex) connection.Delete(jump); app.NotifyAll(msgDeleted, name); return Log.Info(Name, "Deleted {0} jump for {1}", name, who.Name); }
bool cmdHelp(VPServices app, Avatar who, string data) { var helpUrl = app.PublicUrl + "help"; if ( data != "" ) { // If given data, try to find specific command and print help in console for // that user foreach ( var cmd in app.Commands ) if ( TRegex.IsMatch(data, cmd.Regex) ) { app.Bot.ConsoleMessage(who.Session, ChatEffect.BoldItalic, VPServices.ColorInfo, "", msgCommandTitle, cmd.Name); app.Bot.ConsoleMessage(who.Session, ChatEffect.Italic, VPServices.ColorInfo, "", msgCommandRgx, cmd.Regex); app.Bot.ConsoleMessage(who.Session, ChatEffect.Italic, VPServices.ColorInfo, "", msgCommandDesc, cmd.Help); app.Bot.ConsoleMessage(who.Session, ChatEffect.Italic, VPServices.ColorInfo, "", msgCommandExample, cmd.Example); return true; } app.Warn(who.Session, "Could not match any command for '{0}'; try {1}", data, helpUrl); return true; } else { // Broadcast help URL for everybody app.NotifyAll("Command help can be found at {0}", helpUrl); return true; } }
bool cmdAddFact(VPServices app, Avatar who, string data) { var matches = Regex.Match(data, "^(-+lock )?(.+?): (.+)$"); if ( !matches.Success ) return false; var parts = matches.ToArray(); var locked = parts[1] != ""; var topic = parts[2].Trim(); var what = parts[3].Trim(); var old = getFact(topic); var msg = old == null ? msgAdded : msgOverwritten; // Only allow overwrite of locked previous factoid if owner or bot owner if ( old != null && old.Locked && !who.Name.IEquals(app.Owner) ) if (old.WhoID != who.Id) { app.Warn(who.Session, msgLocked, old.WhoID); return true; } lock (app.DataMutex) { connection.Execute("DELETE FROM Facts WHERE Topic = ? COLLATE NOCASE", topic); connection.Insert( new sqlFact { Topic = topic, Description = what, When = DateTime.Now, WhoID = who.Id, Locked = locked }); } app.Notify(who.Session, msg, topic, locked ? "locked " : ""); return Log.Info(Name, "Saved a fact from {0} for topic {1} (locked: {2})", who.Name, topic, locked); }
bool cmdGetFact(VPServices app, Avatar who, string data) { var fact = getFact(data); // Undefined topics if (fact == null) { app.Warn(who.Session, msgNonExistant); return true; } // Alias topics if ( fact.Description.StartsWith("@") ) { var aliasTopic = fact.Description.Substring(1); var alias = getFact(aliasTopic); if (alias == null) { app.Warn(who.Session, msgBrokenAlias, aliasTopic, data); return true; } app.NotifyAll(msgFact, alias.Topic, alias.Description); return true; } app.NotifyAll(msgFact, fact.Topic, fact.Description); return true; }
bool onRequest(VPServices app, Avatar source, string targetName, bool invite) { // Ignore if self if ( source.Name.IEquals(targetName) ) { app.Warn(source.Session, msgSelf); return true; } // Reject if source has request if ( !isRequestee(source.Session).Equals(JoinInvite.Nobody) ) { app.Warn(source.Session, msgPendingRequester); return Log.Info(Name, "Rejecting request by {0} as they already have one pending", source); } // Reject if target has request if ( !isRequested(targetName).Equals(JoinInvite.Nobody) ) { app.Warn(source.Session, msgPendingRequestee); return Log.Info(Name, "Rejecting request by {0} as they already have one pending", source); } // Ignore if no such users found var action = invite ? "invite" : "join"; var targets = app.GetUsers(targetName); if ( targets.Length <= 0 ) { app.Warn(source.Session, msgNotPresent); return true; } // Request all sessions of given name foreach (var target in targets) app.Notify(target.Session, msgRequest, source.Name, action); app.Notify(source.Session, msgRequestSent, targetName); requests.Add(new JoinInvite { By = source.Session, Who = targetName.ToLower(), When = DateTime.Now, Invite = invite }); return true; }
bool cmdDeprecated(VPServices app, Avatar who, string data) { app.Warn(who.Session, "The !back and !forward commands are no longer in use; please use VP 0.3.34 for teleport history"); return true; }
bool cmdJump(VPServices app, Avatar who, string data) { var jumpsUrl = app.PublicUrl + webJumps; var name = data.ToLower(); // Reject null if ( name == "" ) return false; lock ( app.DataMutex ) { var jump = ( name == "random" ) ? connection.Query<sqlJump>("SELECT * FROM Jumps ORDER BY RANDOM() LIMIT 1;").FirstOrDefault() : getJump(name); if ( jump != null ) app.Bot.Avatars.Teleport(who.Session, "", new Vector3(jump.X, jump.Y, jump.Z), jump.Yaw, jump.Pitch); else app.Warn(who.Session, msgNonExistant, jumpsUrl); } return true; }
bool cmdReadTelegrams(VPServices app, Avatar who, string data) { var grams = getUnread(who.Name); if ( grams.Count() <= 0 ) { app.Warn(who.Session, msgNoTelegrams); return true; } lock ( app.DataMutex ) { connection.BeginTransaction(); foreach ( var gram in grams ) { app.Bot.ConsoleMessage(who.Session, ChatEffect.Bold, VPServices.ColorAlert, "", msgTelegram, gram.Source, gram.When); app.Bot.ConsoleMessage(who.Session, ChatEffect.None, VPServices.ColorAlert, "", gram.Message); app.Bot.ConsoleMessage(who.Session, ChatEffect.None, VPServices.ColorAlert, "", ""); gram.Read = true; connection.Update(gram); } connection.Commit(); } return true; }
bool cmdReadTelegrams(VPServices app, Avatar who, string data) { var grams = from tg in storedTelegrams where tg.To.IEquals(who.Name) select tg; if ( grams.Count() <= 0 ) { app.Warn(who.Session, msgNoTelegrams); return true; } foreach ( var gram in grams ) { app.Bot.ConsoleMessage(who.Session, ChatEffect.Bold, VPServices.ColorAlert, "", msgTelegram, gram.From, gram.When); app.Bot.ConsoleMessage(who.Session, ChatEffect.None, VPServices.ColorAlert, "", gram.Message); app.Bot.ConsoleMessage(who.Session, ChatEffect.None, VPServices.ColorAlert, "", ""); } storedTelegrams.RemoveAll((tg) => { return tg.To.IEquals(who.Name); }); saveTelegrams(); return true; }
bool cmdJumpList(VPServices app, Avatar who, string data) { var jumpsUrl = app.PublicUrl + webJumps; // No search; list URL only if ( data == "" ) { app.Notify(who.Session, jumpsUrl); return true; } lock ( app.DataMutex ) { var query = from j in connection.Table<sqlJump>() where j.Name.Contains(data) select j; // No results if ( query.Count() <= 0 ) { app.Warn(who.Session, msgNoResults, jumpsUrl); return true; } // Iterate results app.Bot.ConsoleMessage(who.Session, ChatEffect.BoldItalic, VPServices.ColorInfo, "", msgResults, data); foreach ( var q in query ) app.Bot.ConsoleMessage(who.Session, ChatEffect.Italic, VPServices.ColorInfo, "", msgResult, q.Name, q.Creator, q.When); } return true; }
bool cmdFinishTodo(VPServices app, Avatar who, string data) { var ids = data.TerseSplit(","); foreach (var entry in ids) { var trimmed = entry.Trim(); int id; if ( !int.TryParse(trimmed, out id) ) { app.Warn(who.Session, msgInvalid, trimmed); continue; } lock (app.DataMutex) { var affected = connection.Execute("UPDATE Todo SET Done = ? WHERE ID = ?", true, id); if ( affected <= 0 ) app.Warn(who.Session, msgNonExistant, id); else Log.Info(Name, "Marked todo #{0} as done for {1}", id, who.Name); } } app.Notify(who.Session, msgDone); return true; }
bool cmdDeleteFact(VPServices app, Avatar who, string data) { var fact = getFact(data); if (fact == null) { app.Warn(who.Session, msgNonExistant); return true; } // Only allow deletion of locked factoid if owner or bot owner if ( fact.Locked && !who.Name.IEquals(app.Owner) ) if (fact.WhoID != who.Id) { app.Warn(who.Session, msgLocked, fact.WhoID); return true; } lock (app.DataMutex) connection.Execute("DELETE FROM Facts WHERE Topic = ? COLLATE NOCASE", data); app.Notify(who.Session, msgDeleted); return Log.Info(Name, "{0} deleted factoid for topic {1}", who.Name, data); }
bool cmdTogglePVP(VPServices app, Avatar who, string data) { var config = app.GetUserSettings(who); bool toggle = false; DateTime lastSwitch; if ( config.Contains(keyLastSwitch) ) lastSwitch = DateTime.Parse(config.Get(keyLastSwitch)); else lastSwitch = DateTime.Now.AddSeconds(-60); // Reject if too soon if ( lastSwitch.SecondsToNow() < 60 ) { var timeLeft = 60 - lastSwitch.SecondsToNow(); app.Warn(who.Session, msgTooSoon, timeLeft); return true; } // Try to parse user given boolean; silently ignore on failure if ( data != "" ) { if ( !VPServices.TryParseBool(data, out toggle) ) return false; } else toggle = !config.GetBoolean(keyMode, false); // Set new boolean, timeout and if new, health config.Set(keyMode, toggle); config.Set(keyLastSwitch, DateTime.Now); if ( !config.Contains(keyHealth) ) config.Set(keyHealth, 100); var verb = toggle ? "enabled" : "disabled"; app.NotifyAll(msgToggle, verb, who.Name); return true; }
bool cmdAddJump(VPServices app, Avatar who, string data) { var name = data.ToLower(); // Reject null entries and reserved words if ( name == "" ) return false; else if ( name == "random" ) { app.Warn(who.Session, msgReserved); return true; } if ( getJump(name) != null ) { app.Warn(who.Session, msgExists); return Log.Debug(Name, "{0} tried to overwrite jump {1}", who.Name, getJump(name).Name); } lock (app.DataMutex) connection.Insert( new sqlJump { Name = name, Creator = who.Name, When = DateTime.Now, X = who.X, Y = who.Y, Z = who.Z, Pitch = who.Pitch, Yaw = who.Yaw }); app.NotifyAll(msgAdded, name, who.X, who.Y, who.Z, who.Yaw, who.Pitch); return Log.Info(Name, "Saved a jump for {0} at {1}, {2}, {3} for {4}", who.Name, who.X, who.Y, who.Z, name); }
bool onResponse(VPServices app, Avatar targetAv, bool yes) { var sourceReq = isRequested(targetAv.Name); // Reject non-requested if ( sourceReq.Equals(JoinInvite.Nobody) ) { app.Warn(targetAv.Session, msgNoRequests); return true; } requests.Remove(sourceReq); // Rejected requests if ( !yes ) { app.Notify(sourceReq.By, msgRequestRejected); return true; } var target = app.GetUser(targetAv.Session); var source = app.GetUser(sourceReq.By); // Reject phantom users if ( target == null ) return true; // Reject if source has gone away if ( source == null ) { app.Warn(targetAv.Session, msgNotPresent); return Log.Info(Name, "Rejecting response by {0} as they have left", source.Name); } var targetPos = sourceReq.Invite ? source.Position : target.Position; var targetSession = sourceReq.Invite ? target.Session : source.Session; var targetMsg = sourceReq.Invite ? msgInvited : msgJoined; app.Notify(target.Session, targetMsg, source.Name); app.Bot.Avatars.Teleport(targetSession, "", new Vector3(targetPos.X, targetPos.Y, targetPos.Z), 0, 0); return true; }
bool cmdTogglePVP(VPServices app, Avatar who, string data) { var lastSwitch = who.GetSettingDateTime(keyLastSwitch); bool toggle = false; // Reject if too soon if ( lastSwitch.SecondsToNow() < 60 ) { var timeLeft = 60 - lastSwitch.SecondsToNow(); app.Warn(who.Session, msgTooSoon, timeLeft); return true; } if ( data != "" ) { // Try to parse user given boolean; silently ignore on failure if ( !VPServices.TryParseBool(data, out toggle) ) return false; } else toggle = !who.GetSettingBool(keyMode); // Set new boolean, timeout and if new, health who.SetSetting(keyMode, toggle); who.SetSetting(keyLastSwitch, DateTime.Now); initialHealth(who); var verb = toggle ? "enabled" : "disabled"; app.NotifyAll(msgToggle, verb, who.Name); return true; }