コード例 #1
0
ファイル: IRC.cs プロジェクト: edwinr/VPServices
        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();
        }
コード例 #2
0
        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
ファイル: Todo.cs プロジェクト: AnthonyNeace/VPServices
        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
ファイル: Jumps.cs プロジェクト: AnthonyNeace/VPServices
        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
ファイル: Home.cs プロジェクト: edwinr/VPServices
        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
ファイル: Home.cs プロジェクト: AnthonyNeace/VPServices
        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
ファイル: Jumps.cs プロジェクト: AnthonyNeace/VPServices
        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
ファイル: Jumps.cs プロジェクト: VirtualParadise/VPServices
        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
ファイル: Jumps.cs プロジェクト: AnthonyNeace/VPServices
        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);
        }
コード例 #17
0
        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
ファイル: Logging.cs プロジェクト: edwinr/VPServices
 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
ファイル: Home.cs プロジェクト: AnthonyNeace/VPServices
        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
ファイル: Trivia.Commands.cs プロジェクト: edwinr/VPServices
        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;
        }
コード例 #21
0
        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
ファイル: Home.cs プロジェクト: VirtualParadise/VPServices
        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
ファイル: WorldSettings.cs プロジェクト: edwinr/VPServices
        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
ファイル: Facts.cs プロジェクト: VirtualParadise/VPServices
        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
ファイル: Greetings.cs プロジェクト: edwinr/VPServices
        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
ファイル: Greetings.cs プロジェクト: AnthonyNeace/VPServices
        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
ファイル: Trivia.Commands.cs プロジェクト: edwinr/VPServices
        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
ファイル: Home.cs プロジェクト: AnthonyNeace/VPServices
        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
ファイル: Ideas.cs プロジェクト: edwinr/VPServices
        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
ファイル: Logging.cs プロジェクト: VirtualParadise/VPServices
        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
ファイル: Home.cs プロジェクト: edwinr/VPServices
        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
ファイル: Trivia.Web.cs プロジェクト: edwinr/VPServices
        /// <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
ファイル: Rkill.cs プロジェクト: VirtualParadise/VPServices
        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
ファイル: WorldSettings.cs プロジェクト: edwinr/VPServices
        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
ファイル: TeleportHistory.cs プロジェクト: edwinr/VPServices
        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
ファイル: Todo.cs プロジェクト: VirtualParadise/VPServices
        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
ファイル: Ideas.cs プロジェクト: edwinr/VPServices
        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);
        }