bool cmdToggle(VPServices app, Avatar who, string data, string key) { string msg = null; bool toggle; if ( data != "" ) { // Try to parse user given boolean; reject command on failure if ( !VPServices.TryParseBool(data, out toggle) ) return false; } else toggle = !who.GetSettingBool(key); who.SetSetting(key, toggle); switch (key) { case SettingGreetMe: msg = toggle ? msgGreetMe : msgGreetMeNot; break; case SettingShowGreets: msg = toggle ? msgShowGreets : msgHideGreets; break; } app.Notify(who.Session, msg); return Log.Debug(Name, "Toggled greet-me for {0} to {1}", who.Name, toggle); }
public void onAvatarLeave(Instance sender, Avatar avatar) { // Write to log userStream.WriteLine("leave,{0},{1}", avatar.Name, (int)DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds); }
bool cmdBounce(VPServices app, Avatar who, string data) { who.SetSetting(settingBounce, true); app.Bot.Avatars.Teleport(who.Session, app.World, who.Position); return Log.Info(Name, "Bounced user {0}", who.Name); }
bool cmdToggle(VPServices app, Avatar who, string data, string key) { var config = app.GetUserSettings(who); string msg = null; bool toggle = false; // Try to parse user given boolean; silently ignore on failure if ( data != "" ) if ( !VPServices.TryParseBool(data, out toggle) ) return false; config.Set(key, toggle); switch (key) { case settingGreetMe: msg = toggle ? msgGreetMe : msgGreetMeNot; break; case settingShowGreets: msg = toggle ? msgShowGreets : msgHideGreets; break; } app.Notify(who.Session, msg); return Log.Debug(Name, "Toggled greet-me for {0} to {1}", who.Name, toggle); }
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 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 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; }
void onAvatarsChange(Instance sender, Avatar avatar) { var user = GetUser(avatar.Session); user.Position = avatar.Position; if ( AvatarChange != null ) AvatarChange(sender, avatar); }
bool cmdReloadTrivia(VPServices app, Avatar who, string data) { entries = null; loadTrivia(); app.Notify(who.Session, msgReloaded, entries.Length); return true; }
void onAvatarAdd(Instance sender, Avatar avatar) { TConsole.WriteLineColored(ConsoleColor.Cyan, "*** {0} [SID#{1}] enters", avatar.Name, avatar.Session); lock (SyncMutex) Users.Add(avatar); if ( AvatarEnter != null ) AvatarEnter(sender, avatar); }
void cmdAddIdea(VPServices serv, Avatar who, string data) { var what = data.Trim(); storedIdeas.Add( new Idea(who.Name, what) ); saveIdeas(); serv.Bot.Say("{0}: Saved", who.Name); Log.Info(Name, "Saved a idea for {0}: {1}", who.Name, what); }
bool cmdReloadTrivia(VPServices app, Avatar who, string data) { entries = null; if ( !loadTrivia() ) app.Bot.Say("Sorry, I was unable to find my trivia database"); else app.Notify(who.Session, msgReloaded, entries.Length); return true; }
void onAvatarLeave(Instance sender, Avatar avatar) { TConsole.WriteLineColored(ConsoleColor.Cyan, "*** {0} [SID#{1}] leaves", avatar.Name, avatar.Session); var user = GetUser(avatar.Session); if ( AvatarLeave != null ) AvatarLeave(sender, avatar); lock (SyncMutex) Users.Remove(user); }
bool cannotHit(Avatar who) { if ( who.X < 1 && who.X > -1 ) if ( who.Z < 1 && who.Z > -1 ) return true; var death = who.GetSettingDateTime(keyDeath); if ( death.SecondsToNow() < 5 ) return true; return false; }
bool cmdClearHome(VPServices app, Avatar who, string data) { var config = app.GetUserSettings(who); if ( config.Contains(settingHome) ) { config.Remove(settingHome); app.Notify(who.Session, "Your home has been cleared to ground zero"); } else app.Notify(who.Session, "You do not have a home location"); return Log.Info(Name, "Cleared home for {0}", who.Name); }
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; } }
void onWorldChat(Instance sender, Avatar user, string message) { // No chat if not connected if (!irc.IsConnected) return; var msgRoll = message.TerseSplit("\n"); foreach (var msg in msgRoll) if ( msg.StartsWith("/me ") ) irc.SendMessage(SendType.Action, config.Channel, user.Name + " " + msg.Substring(4) ); else irc.SendMessage(SendType.Message, config.Channel, user.Name + ": " + msg ); }
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; }
void onWorldLeave(Instance sender, Avatar avatar) { if (!irc.IsConnected) return; // No greetings within 10 seconds of bot load, to prevent flooding of entries // on initial user list load if ( VPServices.App.LastConnect.SecondsToNow() < 10 ) return; // Reject for those who have greetme off var greets = app.GetService<Greetings>(); if ( greets != null && !greets.CanGreet(avatar) ) return; var msg = msgPart.LFormat(avatar.Name, VPServices.App.World); irc.SendMessage(SendType.Action, config.Channel, msg); }
bool cannotHit(Avatar who) { if ( who.X < 1 && who.X > -1 ) if ( who.Z < 1 && who.Z > -1 ) return true; DateTime death; var config = app.GetUserSettings(who); if ( config.Contains(keyDeath) ) death = DateTime.Parse(config.Get(keyDeath)); else death = DateTime.Now.AddSeconds(-6); if ( death.SecondsToNow() < 5 ) return true; return false; }
void cmdDoneIdea(VPServices serv, Avatar who, string data) { uint id; if ( !uint.TryParse(data, out id) ) return; var idea = getIdea(id); if ( idea.ID == 0 ) { serv.Bot.Say("{0}: Idea does not exist", who.Name); return; } else if ( idea.Done ) return; else idea.Done = true; saveIdeas(); serv.Bot.Say("{0}: Idea marked as done", who.Name); Log.Info(Name, "Marked {0} idea as done for {1}", id, 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 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); }
void cmdIdea(VPServices serv, Avatar who, string data) { try { var idea = from i in storedIdeas where !i.Done select i; var random = idea .Skip(VPServices.Rand.Next(0, storedIdeas.Count)) .Take(1) .Single(); serv.Bot.Say("From {0} (#{1}): {2}", random.Who, random.ID, random.What); } catch { serv.Bot.Say("{0}: I am unable to fetch an idea (perhaps they are all done?)", who.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 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; }
void cmdGoHome(VPServices app, Avatar who, bool entering) { AvatarPosition target; var query = from h in connection.Table<sqlHome>() where h.UserID == who.Id select h; var home = query.FirstOrDefault(); if (home == null && entering) return; if (home != null) target = new AvatarPosition(home.X, home.Y, home.Z, home.Pitch, home.Yaw); else target = AvatarPosition.GroundZero; app.Bot.Avatars.Teleport(who.Session, "", target); Log.Debug(Name, "Teleported {0} home at {1:f3}, {2:f3}, {3:f3}", who.Name, target.X, target.Y, target.Z); }
bool cmdClearHome(VPServices app, Avatar who, string data) { lock (app.DataMutex) connection.Execute("DELETE FROM Home WHERE UserID = ?", who.Id); app.Notify(who.Session, "Your home has been cleared to ground zero"); return Log.Info(Name, "Cleared home for {0}", who.Name); }
void onLeave(Instance sender, Avatar who) { // Keep track of LastExit to prevent annoying users who.SetSetting(settingLastExit, DateTime.Now); }