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 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 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)); }
void gameTimeout() { while (inProgress) { if (progressSince.SecondsToNow() >= 60) { lock ( mutex ) { gameEnd(); app.NotifyAll("Timeout! The answer was {0}.", entryInPlay.CanonicalAnswer); Log.Debug(tag, "Question timed out"); } } Thread.Sleep(500); } }
bool cmdVersion(VPServices app, Avatar who, string data) { var asm = Assembly.GetExecutingAssembly().Location; var fileDate = File.GetLastWriteTime(asm); app.NotifyAll("I was built on {0}", fileDate); return(true); }
void connect(VPServices app) { lock (mutex) { app.NotifyAll(msgConnecting, app.World, config.Channel, config.Host); Log.Info(Name, "Creating and establishing IRC bridge..."); try { irc.Connect(config.Host, config.Port); irc.Login(config.NickName, config.RealName); Log.Debug(Name, "Connected and logged into {0}", config.Host); } catch (Exception e) { // Ensure disconnection if (irc.IsConnected) { irc.Disconnect(); } app.WarnAll(msgConnectError, e.Message); Log.Warn(Name, "Could not login to IRC: {0}", e.Message); return; } try { irc.RfcJoin(config.Channel); Log.Debug(Name, "Joined channel {0}", config.Channel); } catch (Exception e) { // Ensure disconnection if (irc.IsConnected) { irc.Disconnect(); } app.WarnAll(msgConnectError, e.Message); Log.Warn(Name, "Could not join channel: {0}", e.Message); return; } // Start IRC task Task.Factory.StartNew(updateLoop); } }
void disconnect(VPServices app) { lock (mutex) { if (!irc.IsConnected) { return; } app.NotifyAll(msgDisconnected, app.World, config.Channel, config.Host); Log.Info(Name, "Disconnecting IRC bridge..."); irc.RfcQuit("Goodbye"); irc.Disconnect(); Log.Debug(Name, "Disconnected IRC bridge"); } }
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 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); }
void disconnect(VPServices app) { lock (mutex) { if (!irc.IsConnected) return; app.NotifyAll(msgDisconnected, app.World, config.Channel, config.Host); Log.Info(Name, "Disconnecting IRC bridge..."); irc.RfcQuit("Goodbye"); irc.Disconnect(); Log.Debug(Name, "Disconnected IRC bridge"); } }
void connect(VPServices app) { lock (mutex) { app.NotifyAll(msgConnecting, app.World, config.Channel, config.Host); Log.Info(Name, "Creating and establishing IRC bridge..."); try { irc.Connect(config.Host, config.Port); irc.Login(config.NickName, config.RealName); Log.Debug(Name, "Connected and logged into {0}", config.Host); } catch (Exception e) { // Ensure disconnection if (irc.IsConnected) irc.Disconnect(); app.WarnAll(msgConnectError, e.Message); Log.Warn(Name, "Could not login to IRC: {0}", e.Message); return; } try { irc.RfcJoin(config.Channel); Log.Debug(Name, "Joined channel {0}", config.Channel); } catch (Exception e) { // Ensure disconnection if (irc.IsConnected) irc.Disconnect(); app.WarnAll(msgConnectError, e.Message); Log.Warn(Name, "Could not join channel: {0}", e.Message); return; } // Start IRC task Task.Factory.StartNew(updateLoop); } }
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 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 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 cmdVersion(VPServices app, Avatar who, string data) { var asm = Assembly.GetExecutingAssembly().Location; var fileDate = File.GetLastWriteTime(asm); app.NotifyAll("I was built on {0}", fileDate); 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 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; }