Пример #1
0
        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;
        }
Пример #2
0
        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;
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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;
        }
Пример #7
0
        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));
        }
Пример #8
0
        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);
        }
Пример #9
0
        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));
        }
Пример #10
0
        bool cmdSendTelegram(VPServices app, Avatar who, string data)
        {
            var matches = Regex.Match(data, "^(.+?): (.+)$");

            if (!matches.Success)
            {
                return(false);
            }

            var target = matches.Groups[1].Value.Trim();
            var msg    = matches.Groups[2].Value.Trim();

            lock (app.DataMutex)
                connection.Insert(new sqlTelegram
                {
                    Source  = who.Name,
                    Target  = target,
                    Message = msg,
                    When    = DateTime.Now,
                    Read    = false
                });

            told[target.ToLower()] = false;
            app.Notify(who.Session, msgTelegramSent, target);
            return(Log.Info(Name, "Recorded from {0} for {1}", who.Name, target));
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }
Пример #13
0
        bool cmdPunchbag(VPServices app, Avatar who, string data)
        {
            app.Bot.GoTo(who.X, who.Y, who.Z);
            app.Notify(who.Session, msgPunchbag);

            return(true);
        }
Пример #14
0
        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));
        }
Пример #15
0
        bool cmdReloadTrivia(VPServices app, Avatar who, string data)
        {
            entries = null;
            loadTrivia();
            app.Notify(who.Session, msgReloaded, entries.Length);

            return true;
        }
Пример #16
0
        bool cmdRandomPos(VPServices app, Avatar who, string data)
        {
            var randX = VPServices.Rand.Next(-65535, 65535);
            var randZ = VPServices.Rand.Next(-65535, 65535);

            app.Notify(who.Session, "Teleporting to {0}, 0, {1}", randX, randZ);
            app.Bot.Avatars.Teleport(who.Session, "", new Vector3(randX, 0, randZ), who.Yaw, who.Pitch);
            return(true);
        }
Пример #17
0
        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);
            }
        }
Пример #18
0
        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);
        }
Пример #19
0
        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;
        }
Пример #20
0
        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);
        }
Пример #21
0
        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);
        }
Пример #22
0
        bool cmdSetHome(VPServices app, Avatar who, string data)
        {
            lock (app.DataMutex)
                connection.InsertOrReplace(new sqlHome
                {
                    UserID = who.Id,
                    X      = who.X,
                    Y      = who.Y,
                    Z      = who.Z,
                    Pitch  = who.Pitch,
                    Yaw    = who.Yaw
                });

            app.Notify(who.Session, "Set your home to {0:f3}, {1:f3}, {2:f3}", who.X, who.Y, who.Z);
            return(Log.Info(Name, "Set home for {0} at {1:f3}, {2:f3}, {3:f3}", who.Name, who.X, who.Y, who.Z));
        }
Пример #23
0
        bool cmdCoords(VPServices app, Avatar who, string data)
        {
            // TODO: move this to the SDK
            var    compass      = (who.Yaw % 360 + 360) % 360;
            string compassPoint = "???";

            if (compass <= 22.5)
            {
                compassPoint = "south";
            }
            else if (compass <= 22.5 + (45 * 1))
            {
                compassPoint = "south-west";
            }
            else if (compass <= 22.5 + (45 * 2))
            {
                compassPoint = "west";
            }
            else if (compass <= 22.5 + (45 * 3))
            {
                compassPoint = "north-west";
            }
            else if (compass <= 22.5 + (45 * 4))
            {
                compassPoint = "north";
            }
            else if (compass <= 22.5 + (45 * 5))
            {
                compassPoint = "north-east";
            }
            else if (compass <= 22.5 + (45 * 6))
            {
                compassPoint = "east";
            }
            else if (compass <= 22.5 + (45 * 7))
            {
                compassPoint = "south-east";
            }
            else if (compass <= 360)
            {
                compassPoint = "south";
            }

            app.Notify(who.Session, "You are at X: {0:f4} Y: {1:f4}a Z: {2:f4}, facing {3} ({4:f0}), pitch {5:f0}", who.X, who.Y, who.Z, compassPoint, who.Yaw, who.Pitch);
            return(true);
        }
Пример #24
0
        bool cmdData(VPServices app, Avatar who, string data)
        {
            var settings = who.GetSettings();

            if (settings.Count <= 0)
            {
                app.Notify(who.Session, msgDataNoResults);
                return(true);
            }

            app.Bot.ConsoleMessage(who.Session, ChatEffect.BoldItalic, VPServices.ColorInfo, "", msgDataResults);
            foreach (var s in settings)
            {
                app.Bot.ConsoleMessage(who.Session, ChatEffect.Italic, VPServices.ColorInfo, "", msgDataResult, s.Key, s.Value);
            }

            return(true);
        }
Пример #25
0
        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));
        }
Пример #26
0
        bool cmdAddTodo(VPServices app, Avatar who, string data)
        {
            if (string.IsNullOrWhiteSpace(data))
            {
                return(false);
            }

            lock (app.DataMutex)
                connection.Insert(new sqlTodo
                {
                    What  = data,
                    When  = DateTime.Now,
                    Who   = who.Name,
                    WhoID = who.Id,
                    Done  = false
                });

            app.Notify(who.Session, msgAdded);
            return(Log.Info(Name, "Saved a todo for {0}: {1}", who.Name, data));
        }
Пример #27
0
        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);
        }
Пример #28
0
        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);
        }
Пример #29
0
        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);
        }
Пример #30
0
        bool cmdData(VPServices app, Avatar who, string data)
        {
            var settings = who.GetSettings();

            if (settings.Count <= 0)
            {
                app.Notify(who.Session, msgDataNoResults);
                return true;
            }

            app.Bot.ConsoleMessage(who.Session, ChatEffect.BoldItalic, VPServices.ColorInfo, "", msgDataResults);
            foreach (var s in settings)
                app.Bot.ConsoleMessage(who.Session, ChatEffect.Italic, VPServices.ColorInfo, "", msgDataResult, s.Key, s.Value);

            return true;
        }
Пример #31
0
 bool cmdHealth(VPServices app, Avatar who, string data)
 {
     initialHealth(who);
     app.Notify(who.Session, msgHealth, who.GetSettingInt(keyHealth));
     return(true);
 }
Пример #32
0
 bool cmdHealth(VPServices app, Avatar who, string data)
 {
     initialHealth(who);
     app.Notify(who.Session, msgHealth, who.GetSettingInt(keyHealth));
     return true;
 }
Пример #33
0
        bool cmdSendTelegram(VPServices app, Avatar who, string data)
        {
            var matches = Regex.Match(data, "^(.+?): (.+)$");
            if ( !matches.Success )
                return false;

            var target = matches.Groups[1].Value.Trim();
            var msg    = matches.Groups[2].Value.Trim();
            var gram   = new Telegram
            {
                From = who.Name,
                To = target,
                Message = msg
            };

            storedTelegrams.Add(gram);
            saveTelegrams();

            app.Notify(who.Session, msgTelegramSent, target);
            return Log.Info(Name, "Recorded from {0} for {1}", who.Name, target);
        }
Пример #34
0
        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;
        }
Пример #35
0
        bool cmdShowUrl(VPServices app, Avatar who, string data)
        {
            app.Notify(who.Session, app.PublicUrl + "scores");

            return(true);
        }
Пример #36
0
        bool cmdSetHome(VPServices app, Avatar who, string data)
        {
            lock (app.DataMutex)
                connection.InsertOrReplace( new sqlHome
                {
                    UserID = who.Id,
                    X      = who.X,
                    Y      = who.Y,
                    Z      = who.Z,
                    Pitch  = who.Pitch,
                    Yaw    = who.Yaw
                });

            app.Notify(who.Session, "Set your home to {0:f3}, {1:f3}, {2:f3}" , who.X, who.Y, who.Z);
            return Log.Info(Name, "Set home for {0} at {1:f3}, {2:f3}, {3:f3}", who.Name, who.X, who.Y, who.Z);
        }
Пример #37
0
        bool cmdSetHome(VPServices app, Avatar who, string data)
        {
            var pos = who.Position.ToString();
            app.GetUserSettings(who).Set(settingHome, pos);

            app.Notify(who.Session, "Set your home to {0:f3}, {1:f3}, {2:f3}" , who.X, who.Y, who.Z);
            return Log.Info(Name, "Set home for {0} at {1:f3}, {2:f3}, {3:f3}", who.Name, who.X, who.Y, who.Z);
        }
Пример #38
0
        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;
        }
Пример #39
0
        bool cmdRandomPos(VPServices app, Avatar who, string data)
        {
            var randX = VPServices.Rand.Next(-65535, 65535);
            var randZ = VPServices.Rand.Next(-65535, 65535);

            app.Notify(who.Session, "Teleporting to {0}, 0, {1}", randX, randZ);
            app.Bot.Avatars.Teleport(who.Session, "", new Vector3(randX, 0, randZ), who.Yaw, who.Pitch);
            return true;
        }
Пример #40
0
        bool cmdPunchbag(VPServices app, Avatar who, string data)
        {
            app.Bot.GoTo(who.X, who.Y, who.Z);
            app.Notify(who.Session, msgPunchbag);

            return true;
        }
Пример #41
0
        bool cmdSendTelegram(VPServices app, Avatar who, string data)
        {
            var matches = Regex.Match(data, "^(.+?): (.+)$");
            if ( !matches.Success )
                return false;

            var target = matches.Groups[1].Value.Trim();
            var msg    = matches.Groups[2].Value.Trim();

            lock (app.DataMutex)
                connection.Insert(new sqlTelegram
                {
                    Source  = who.Name,
                    Target  = target,
                    Message = msg,
                    When    = DateTime.Now,
                    Read    = false
                });

            told[target.ToLower()] = false;
            app.Notify(who.Session, msgTelegramSent, target);
            return Log.Info(Name, "Recorded from {0} for {1}", who.Name, target);
        }
Пример #42
0
        bool cmdShowUrl(VPServices app, Avatar who, string data)
        {
            app.Notify(who.Session, app.PublicUrl + "scores");

            return true;
        }
Пример #43
0
        bool cmdCoords(VPServices app, Avatar who, string data)
        {
            // TODO: move this to the SDK
            var compass = (who.Yaw % 360 + 360) % 360;
            string compassPoint = "???";

            if      ( compass <= 22.5 )            compassPoint = "south";
            else if ( compass <= 22.5 + (45 * 1) ) compassPoint = "south-west";
            else if ( compass <= 22.5 + (45 * 2) ) compassPoint = "west";
            else if ( compass <= 22.5 + (45 * 3) ) compassPoint = "north-west";
            else if ( compass <= 22.5 + (45 * 4) ) compassPoint = "north";
            else if ( compass <= 22.5 + (45 * 5) ) compassPoint = "north-east";
            else if ( compass <= 22.5 + (45 * 6) ) compassPoint = "east";
            else if ( compass <= 22.5 + (45 * 7) ) compassPoint = "south-east";
            else if ( compass <= 360 )             compassPoint = "south";

            app.Notify(who.Session, "You are at {0:f4}, {1:f4}, {2:f4}, facing {3} ({4:f0}), pitch {5:f0}", who.X, who.Y, who.Z, compassPoint, who.Yaw, who.Pitch);
            return true;
        }
Пример #44
0
        bool cmdHealth(VPServices app, Avatar who, string data)
        {
            var config = app.GetUserSettings(who);
            var health = config.GetInt(keyHealth, 100);

            app.Notify(who.Session, msgHealth, health);
            return true;
        }
Пример #45
0
        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;
            }
        }
Пример #46
0
        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;
        }
Пример #47
0
        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);
        }
Пример #48
0
        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;
        }
Пример #49
0
        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;
        }
Пример #50
0
        bool cmdAddTodo(VPServices app, Avatar who, string data)
        {
            if ( string.IsNullOrWhiteSpace(data) )
                return false;

            lock (app.DataMutex)
                connection.Insert( new sqlTodo
                {
                    What  = data,
                    When  = DateTime.Now,
                    Who   = who.Name,
                    WhoID = who.Id,
                    Done  = false
                });

            app.Notify(who.Session, msgAdded);
            return Log.Info(Name, "Saved a todo for {0}: {1}", who.Name, data);
        }