Пример #1
0
        public void Init(VPServices app, Instance bot)
        {
            app.Commands.AddRange(new[] {
                new Command
                (
                    "IRC: Connect", "^irc(start|connect)$",
                    (s,a,d) => { return connect(); },
                    @"Starts the IRC-VP bridge", "!ircstart", 60
                ),

                new Command
                (
                    "IRC: Disconnect", "^irc(end|disconnect)$",
                    (s,a,d) => { return disconnect(); },
                    @"Stops the IRC-VP bridge", "!ircend", 60
                )
            });

            config = app.Settings.Configs["IRC"] ?? app.Settings.Configs.Add("IRC");

            this.app  = app;
            host      = config.Get("Server", "irc.ablivion.net");
            port      = config.GetInt("Port", 6667);
            channel   = config.Get("Channel", "#vp");
            bot.Chat += onWorldChat;

            if (config.GetBoolean("Autoconnect", false))
                connect();
        }
        void migDatToSQLite(VPServices app)
        {
            var fileJumps = "Jumps.dat";
            string[] lines;
            string   backup;

            if ( !File.Exists(fileJumps) )
                return;

            connection.BeginTransaction();
            lines = File.ReadAllLines(fileJumps);

            foreach ( var line in lines )
            {
                var parts = line.TerseSplit(',');
                connection.Insert(new sqlJump
                {
                    Name    = parts[0],
                    X       = float.Parse(parts[1], CultureInfo.InvariantCulture),
                    Y       = float.Parse(parts[2], CultureInfo.InvariantCulture),
                    Z       = float.Parse(parts[3], CultureInfo.InvariantCulture),
                    Yaw     = float.Parse(parts[4], CultureInfo.InvariantCulture),
                    Pitch   = float.Parse(parts[5], CultureInfo.InvariantCulture),
                    When    = TDateTime.UnixEpoch,
                    Creator = "Unknown"
                });
            }

            connection.Commit();

            backup = fileJumps + ".bak";
            File.Move(fileJumps, backup);
            Log.Debug(Name, "Migrated .dat jump list to SQLite; backed up to '{0}'", backup);
        }
Пример #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 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);
        }
Пример #5
0
        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));
        }
Пример #6
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;
        }
Пример #7
0
        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);
        }
Пример #8
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));
        }
Пример #9
0
        public void Init(VPServices app, Instance bot)
        {
            app.Commands.AddRange(new[] {
                new Command
                (
                    "Home: Set", "^sethome$", cmdSetHome,
                    @"Sets user's home position, where they will be teleported to every time they enter the world",
                    @"!sethome"
                ),

                new Command
                (
                    "Home: Teleport", "^home$", cmdGoHome,
                    @"Teleports user to their home position, or ground zero if unset",
                    @"!home"
                ),

                new Command
                (
                    "Home: Clear", "^clearhome$", cmdClearHome,
                    @"Clears user's home position",
                    @"!clearhome"
                ),

                new Command
                (
                    "Teleport: Bounce", "^bounce$", cmdBounce,
                    @"Disconnects and reconnects user to the world; useful for clearing the download queue and fixing some issues",
                    @"!bounce"
                ),
            });

            bot.Avatars.Enter += onEnter;
        }
Пример #10
0
        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);
        }
Пример #11
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);
        }
Пример #12
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));
        }
Пример #13
0
        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);
            }
        }
Пример #14
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);
        }
Пример #15
0
        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);
        }
Пример #16
0
        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);
        }
        void migDatToSQLite(VPServices app)
        {
            var fileTelegrams = "Telegrams.dat";

            if (!File.Exists(fileTelegrams))
            {
                return;
            }

            #region Telegram transaction
            connection.BeginTransaction();
            var lines = File.ReadAllLines(fileTelegrams);

            foreach (var line in lines)
            {
                var parts = line.TerseSplit(',');
                connection.Insert(new sqlTelegram
                {
                    Read    = false,
                    Target  = parts[0],
                    Source  = parts[1],
                    Message = parts[2].Replace("%COMMA", ","),
                    When    = parts.Length == 4
                        ? DateTime.Parse(parts[3])
                        : DateTime.MinValue
                });
            }

            connection.Commit();
            #endregion

            var backup = fileTelegrams + ".bak";
            File.Move(fileTelegrams, backup);
            Log.Debug(Name, "Migrated .dat telegrams to SQLite; backed up to '{0}'", backup);
        }
Пример #18
0
 public void Init(VPServices app, Instance bot)
 {
     bot.Property.ObjectCreate += onObjChange;
     bot.Property.ObjectChange += onObjChange;
     bot.Avatars.Enter += onAvatarEnter;
     bot.Avatars.Leave += onAvatarLeave;
 }
Пример #19
0
        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));
        }
Пример #20
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;
        }
        void migDatToSQLite(VPServices app)
        {
            var fileTelegrams = "Telegrams.dat";

            if ( !File.Exists(fileTelegrams) )
                return;

            #region Telegram transaction
            connection.BeginTransaction();
            var lines = File.ReadAllLines(fileTelegrams);

            foreach ( var line in lines )
            {
                var parts = line.TerseSplit(',');
                connection.Insert(new sqlTelegram
                {
                    Read    = false,
                    Target      = parts[0],
                    Source  = parts[1],
                    Message = parts[2].Replace("%COMMA", ","),
                    When    = parts.Length == 4
                        ? DateTime.Parse(parts[3])
                        : DateTime.MinValue
                });
            }

            connection.Commit();
            #endregion

            var backup = fileTelegrams + ".bak";
            File.Move(fileTelegrams, backup);
            Log.Debug(Name, "Migrated .dat telegrams to SQLite; backed up to '{0}'", backup);
        }
Пример #22
0
        void migDatToSQLite(VPServices app)
        {
            var fileIdeas = "Ideas.dat";

            string[] lines;
            string   backup;

            if (!File.Exists(fileIdeas))
            {
                return;
            }

            connection.BeginTransaction();
            lines = File.ReadAllLines(fileIdeas);

            foreach (var line in lines)
            {
                var parts = line.TerseSplit(',');
                connection.Insert(new sqlTodo
                {
                    WhoID = 0,
                    Who   = parts[0],
                    What  = parts[1].Replace("%COMMA%", ","),
                    When  = DateTime.Parse(parts[2]),
                    Done  = bool.Parse(parts[3])
                });
            }

            connection.Commit();

            backup = fileIdeas + ".bak";
            File.Move(fileIdeas, backup);
            Log.Debug(Name, "Migrated .dat ideas list to SQLite; backed up to '{0}'", backup);
        }
Пример #23
0
        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);
        }
Пример #24
0
        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);
        }
Пример #25
0
        void migDatToSQLite(VPServices app)
        {
            var fileIdeas = "Ideas.dat";
            string[] lines;
            string   backup;

            if ( !File.Exists(fileIdeas) )
                return;

            connection.BeginTransaction();
            lines = File.ReadAllLines(fileIdeas);

            foreach ( var line in lines )
            {
                var parts = line.TerseSplit(',');
                connection.Insert(new sqlTodo
                {
                    WhoID = 0,
                    Who   = parts[0],
                    What  = parts[1].Replace("%COMMA%", ","),
                    When  = DateTime.Parse(parts[2]),
                    Done  = bool.Parse(parts[3])
                });
            }

            connection.Commit();

            backup = fileIdeas + ".bak";
            File.Move(fileIdeas, backup);
            Log.Debug(Name, "Migrated .dat ideas list to SQLite; backed up to '{0}'", backup);
        }
Пример #26
0
        public void Init(VPServices app, Instance bot)
        {
            bot.Data.GetWorldSetting += onWorldSetting;

            app.Routes.Add(new WebRoute("WorldSettings", "^worldsettings?$", webWorldSettings,
                @"Provides a key-value list of the settings of the bot's world"));
        }
Пример #27
0
        public void   Init(VPServices app, Instance bot)
        {
            bot.Data.GetWorldSetting += onWorldSetting;

            app.Routes.Add(new WebRoute("WorldSettings", "^worldsettings?$", webWorldSettings,
                                        @"Provides a key-value list of the settings of the bot's world"));
        }
Пример #28
0
        public void Init(VPServices app, Instance bot)
        {
            app.Commands.AddRange(new[] {
                new Command
                (
                    "Facts: Add", "^(addfact|af|define)$", cmdAddFact,
                    @"Adds or overwrites a factoid for a topic, allowing it to be locked or alias another topic",
                    @"!addfact [--lock] `topic: [what|@alias]`"
                ),

                new Command
                (
                    "Facts: Delete", "^(del(ete)?fact|df)$", cmdDeleteFact,
                    @"Clears a factoid for a topic",
                    @"!delfact `topic`"
                ),

                new Command
                (
                    "Facts: Get", "^(what(is)?|explain|fact)$", cmdGetFact,
                    @"Explains a given topic",
                    "!what `topic`"
                ),
            });

            app.Routes.Add(new WebRoute("Facts", "^(list)?facts?$", webListFacts,
                @"Provides a list of defined facts"));

            this.connection = app.Connection;
        }
Пример #29
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);
        }
Пример #30
0
        public void Init(VPServices app, Instance bot)
        {
            this.app = app;

            app.Commands.AddRange(new[] {
                new Command
                (
                    "Swordfight: Toggle", "^swordfight", cmdTogglePVP,
                    @"Toggles or sets swordfighting (PVP) mode for you",
                    @"!swordfight `[true|false]`"
                ),

                new Command
                (
                    "Swordfight: Punchbag", "^punchbag", cmdPunchbag,
                    @"Brings me to user's location to practise swordfighting",
                    @"!punchbag", 5
                ),

                new Command
                (
                    "Swordfight: Health", "^health", cmdHealth,
                    @"Notifys the user of their health",
                    @"!health"
                )
            });

            app.Bot.Property.CallbackObjectCreate += onCreate;
            app.Bot.Avatars.Clicked += onClick;
            app.AvatarEnter         += onEnter;
        }
Пример #31
0
        public void Init(VPServices app, Instance bot)
        {
            this.app = app;

            app.Commands.AddRange( new[] {
                new Command
                (
                    "Swordfight: Toggle", "^swordfight", cmdTogglePVP,
                    @"Toggles or sets swordfighting (PVP) mode for you",
                    @"!swordfight `[true|false]`"
                ),

                new Command
                (
                    "Swordfight: Punchbag", "^punchbag", cmdPunchbag,
                    @"Brings me to user's location to practise swordfighting",
                    @"!punchbag", 5
                ),

                new Command
                (
                    "Swordfight: Health", "^health", cmdHealth,
                    @"Notifys the user of their health",
                    @"!health"
                )
            });

            app.Bot.Property.CallbackObjectCreate += onCreate;
            app.Bot.Avatars.Clicked               += onClick;
            app.AvatarEnter                       += onEnter;
        }
Пример #32
0
        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);
        }
Пример #33
0
        public void Init(VPServices app, Instance bot)
        {
            app.Commands.AddRange(new[] {
                new Command
                (
                    "Facts: Add", "^(addfact|af|define)$", cmdAddFact,
                    @"Adds or overwrites a factoid for a topic, allowing it to be locked or alias another topic",
                    @"!addfact [--lock] `topic: [what|@alias]`"
                ),

                new Command
                (
                    "Facts: Delete", "^(del(ete)?fact|df)$", cmdDeleteFact,
                    @"Clears a factoid for a topic",
                    @"!delfact `topic`"
                ),

                new Command
                (
                    "Facts: Get", "^(what(is)?|explain|fact)$", cmdGetFact,
                    @"Explains a given topic",
                    "!what `topic`"
                ),
            });

            app.Routes.Add(new WebRoute("Facts", "^(list)?facts?$", webListFacts,
                                        @"Provides a list of defined facts"));

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

            return true;
        }
Пример #36
0
        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);
        }
Пример #37
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));
        }
Пример #38
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);
        }
Пример #39
0
        public void Init(VPServices app, Instance bot)
        {
            bot.Property.ObjectCreate += (s, i, o) => { objectEvent(o, sqlBuildType.Create); };
            bot.Property.ObjectChange += (s, i, o) => { objectEvent(o, sqlBuildType.Modify); };
            bot.Property.ObjectDelete += onObjDelete;
            app.AvatarEnter           += (s, a) => { userEvent(a, sqlUserType.Enter); };
            app.AvatarLeave           += (s, a) => { userEvent(a, sqlUserType.Leave); };

            this.connection = app.Connection;
        }
Пример #40
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;
        }
Пример #41
0
        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);
        }
Пример #42
0
        public void Init(VPServices app, Instance bot)
        {
            bot.Property.ObjectCreate += (s,i,o) => { objectEvent(o, sqlBuildType.Create); };
            bot.Property.ObjectChange += (s,i,o) => { objectEvent(o, sqlBuildType.Modify); };
            bot.Property.ObjectDelete += onObjDelete;
            app.AvatarEnter           += (s,a) => { userEvent(a, sqlUserType.Enter); };
            app.AvatarLeave           += (s,a) => { userEvent(a, sqlUserType.Leave); };

            this.connection = app.Connection;
        }
Пример #43
0
        public void Migrate(VPServices app, int target)
        {
            this.connection = app.Connection;

            switch (target)
            {
            case 2:
                migSetupSQLite(app);
                break;
            }
        }
Пример #44
0
        public void Migrate(VPServices app, int target)
        {
            this.connection = app.Connection;

            switch (target)
            {
                case 2:
                    migSetupSQLite(app);
                    break;
            }
        }
Пример #45
0
        bool cmdCrash(VPServices app, Avatar who, string data)
        {
            var owner = app.NetworkSettings.Get("Username");

            if (!who.Name.IEquals(owner))
            {
                return(false);
            }

            app.Crash = true;
            return(true);
        }
Пример #46
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);
        }
Пример #47
0
        /// <summary>
        /// Web route that lists scores of trivia players
        /// </summary>
        string webListScores(VPServices app, string data)
        {
            string listing = "# Trivia scores:\n";
            var    scores  = from IConfig c in app.UserSettings.Configs
                             where   c.Contains(keyTriviaPoints) && c.GetInt(keyTriviaPoints) > 0
                             orderby c.GetInt(keyTriviaPoints) descending
                             select new Tuple<int, string> ( c.GetInt(keyTriviaPoints), c.Name );

            foreach (var score in scores)
                listing += "* **{0}** : {1} point(s)\n\n".LFormat(score.Item2, score.Item1);

            return app.MarkdownParser.Transform(listing);
        }
Пример #48
0
        /// <summary>
        /// Web route that lists scores of trivia players
        /// </summary>
        string webListScores(VPServices app, string data)
        {
            var listing = "# Trivia scores:\n";
            var query   = from   s in app.Connection.Table<sqlUserSettings>()
                          where  s.Name == keyTriviaPoints
                          select s;

            // XXX: ID only; investigate getting names
            foreach (var score in query)
                listing += "* **{0}** : {1} point(s)\n\n".LFormat(score.UserID, score.Value);

            return app.MarkdownParser.Transform(listing);
        }
Пример #49
0
        public void Init(VPServices app, Instance bot)
        {
            app.Commands.AddRange(new[] {
                new Command
                (
                    "Services: RKill", "^rkill$", cmdRKill,
                    @"Kills a Services bot by name; restricted to set users",
                    @"!rkill `name`"
                ),
            });

            config = app.Settings.Configs["RKill"] ?? app.Settings.AddConfig("RKill");
        }
Пример #50
0
        public void Init(VPServices app, Instance bot)
        {
            app.Commands.AddRange(new[] {
                new Command
                (
                    "Services: RKill", "^rkill$", cmdRKill,
                    @"Kills a Services bot by name; restricted to set users",
                    @"!rkill `name`"
                ),
            });

            config = app.Settings.Configs["RKill"] ?? app.Settings.AddConfig("RKill");
        }
Пример #51
0
        string webWorldSettings(VPServices app, string data)
        {
            string listing = string.Format("# Settings for world '{0}':\n", app.World);

            foreach (var setting in Data)
            {
                if ( setting.Key.Equals("objectpassword", StringComparison.CurrentCultureIgnoreCase) )
                    listing += "* *Object password hidden*\n";
                else
                    listing += string.Format("* **{0}** : {1}\n", setting.Key, setting.Value);
            }

            return app.MarkdownParser.Transform(listing);
        }
Пример #52
0
        bool cmdIRCDisconnect(VPServices app, Avatar who, string data)
        {
            lock (mutex)
            {
                if (!irc.IsConnected)
                {
                    app.Warn(who.Session, msgNotConnected);
                    return(true);
                }

                disconnect(app);
                return(true);
            }
        }
Пример #53
0
        bool cmdIRCDisconnect(VPServices app, Avatar who, string data)
        {
            lock (mutex)
            {
                if (!irc.IsConnected)
                {
                    app.Warn(who.Session, msgNotConnected);
                    return true;
                }

                disconnect(app);
                return true;
            }
        }
Пример #54
0
        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;
            }
        }
Пример #55
0
        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);
            }
        }
Пример #56
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);
        }
Пример #57
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;
        }
Пример #58
0
        public void Init(VPServices app, Instance bot)
        {
            app.Commands.AddRange(new[] {
                new Command
                (
                    "History: Go back", "^(ba?ck|prev)$", cmdDeprecated,
                    @"DEPRECATED; please use VP 0.3.34 for teleport history"
                ),

                new Command
                (
                    "History: Go forward", "^(forward|fwd)$", cmdDeprecated,
                    @"DEPRECATED; please use VP 0.3.34 for teleport history"
                ),
            });
        }
Пример #59
0
        public void Init(VPServices app, Instance bot)
        {
            app.Commands.AddRange(new[] {
                new Command
                (
                    "Todo: Add", "^(addtodo|atd|todoadd)$", cmdAddTodo,
                    @"Adds an attributed and timestamped todo entry",
                    @"!todoadd `entry`"
                ),

                new Command
                (
                    "Todo: Finish", "^(tododone|finishtodo)$", cmdFinishTodo,
                    @"Marks a single or multiple todo entries as finished",
                    @"!tododone `id[, id, [...]]`"
                ),

                new Command
                (
                    "Todo: Delete", "^(tododel(ete)?|deltodo|dtd)$", cmdDeleteTodo,
                    @"Deletes a single or multiple todo entries",
                    @"!tododel `id[, id, [...]]`"
                ),

                new Command
                (
                    "Todo: List", "^(listtodos?|ltd|todolist)$", cmdListTodo,
                    @"Prints the URL to the todo list to chat or lists those matching a search term to you",
                    @"!todolist `[search]`"
                ),

                new Command
                (
                    "Todo: Get random", "^todo$", cmdGetTodo,
                    @"Spins the todo wheel and gives you a random unfinished todo",
                    "!todo"
                ),
            });

            app.Routes.Add(new WebRoute("Todo", "^(list)?todos?$", webListTodos,
                @"Provides a list of todo entries"));

            this.connection = app.Connection;
        }
Пример #60
0
        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);
        }