Exemplo n.º 1
0
        /// <summary>
        /// Generates default command name->method pairs.
        /// </summary>
        void DefaultCommands(DiscordBot bot)
        {
            AdminCommands   adminCmds = new AdminCommands();
            MetaCommands    metaCmds  = new MetaCommands();
            UtilityCommands utilCmds  = new UtilityCommands();
            CoreCommands    coreCmds  = new CoreCommands(IsBotCommander);

            // Informational
            bot.RegisterCommand(InfoCmds.CMD_Help, "help", "halp", "helps", "halps", "hel", "hal", "h");
            bot.RegisterCommand(InfoCmds.CMD_Hello, "hello", "hi", "hey", "source", "src");
            bot.RegisterCommand(InfoCmds.CMD_Info, "info", "notice", "alert");
            bot.RegisterCommand(InfoCmds.CMD_Update, "update", "latest", "current", "build", "builds", "download", "version");
            bot.RegisterCommand(InfoCmds.CMD_GitHub, "github", "git", "gh", "readme", "read", "link");
            bot.RegisterCommand(InfoCmds.CMD_Issues, "issues", "issue", "error", "ghissues", "githubissues");
            bot.RegisterCommand(InfoCmds.CMD_Rule, "rule", "rules");
            bot.RegisterCommand(InfoCmds.CMD_Quote, "quote", "quotes", "q");
            // Meta Docs
            bot.RegisterCommand(metaCmds.CMD_Command, "command", "commands", "cmd", "cmds", "c");
            bot.RegisterCommand(metaCmds.CMD_Mechanism, "mechanism", "mechanisms", "mech", "mechs", "mec", "mecs", "m");
            bot.RegisterCommand(metaCmds.CMD_Tag, "tag", "tags", "t");
            bot.RegisterCommand(metaCmds.CMD_Event, "event", "events", "evt", "evts", "e");
            bot.RegisterCommand(metaCmds.CMD_Action, "action", "actions", "act", "acts", "a");
            bot.RegisterCommand(metaCmds.CMD_Language, "language", "languages", "lang", "langs", "l");
            bot.RegisterCommand(metaCmds.CMD_Guide, "guide", "guides", "g", "beginner", "beginners", "beginnersguide", "guidepage", "guidespage");
            bot.RegisterCommand(metaCmds.CMD_Search, "search", "s", "find", "f", "get", "locate", "what", "where", "how",
                                "w", "meta", "metainfo", "docs", "doc", "documentation", "documentations", "document", "documents");
            // Utility
            bot.RegisterCommand(utilCmds.CMD_LogCheck, "logcheck", "checklog", "logscheck", "checklogs");
            bot.RegisterCommand(utilCmds.CMD_VersionCheck, "versioncheck", "checkversion", "iscurrent", "isuptodate", "isupdated", "checkcurrent", "currentcheck");
            bot.RegisterCommand(utilCmds.CMD_ScriptCheck, "script", "scriptcheck", "dscript", "ds", "checkscript", "dscriptcheck", "checkdscript");
            // Admin
            bot.RegisterCommand(coreCmds.CMD_Restart, "restart");
            bot.RegisterCommand(adminCmds.CMD_Reload, "reload");
        }
 /// <summary>
 /// Software entry point - starts the bot.
 /// </summary>
 static void Main(string[] args)
 {
     DiscordBotBaseHelper.StartBotHandler(args, new DiscordBotConfig()
     {
         CommandPrefix = "!",
         Initialize    = (bot) =>
         {
             InfoCommands infoCommands = new InfoCommands()
             {
                 Bot = bot
             };
             VotingCommands voteCommands = new VotingCommands()
             {
                 Bot = bot
             };
             CoreCommands coreCommands = new CoreCommands(IsAdmin)
             {
                 Bot = bot
             };
             AdminCommands adminCommands = new AdminCommands()
             {
                 Bot = bot
             };
             OwningGuildID     = bot.ConfigFile.GetUlong("guild_id").Value;
             VoteTopicsSection = bot.ConfigFile.GetSection("vote_topics");
             if (VoteTopicsSection == null)
             {
                 VoteTopicsSection = new FDSSection();
                 bot.ConfigFile.Set("vote_topics", VoteTopicsSection);
             }
             Admins = new HashSet <ulong>(bot.ConfigFile.GetStringList("admins").Select(s => ulong.Parse(s)));
             // Info
             bot.RegisterCommand(infoCommands.CMD_Help, "help", "halp", "hlp", "hal", "hel", "h", "?", "use", "usage");
             bot.RegisterCommand(infoCommands.CMD_Hello, "hello", "hi", "whoareyou", "what", "link", "info");
             // Voting
             bot.RegisterCommand(voteCommands.CMD_Ballot, "ballot", "b");
             bot.RegisterCommand(voteCommands.CMD_Vote, "vote", "v");
             bot.RegisterCommand(voteCommands.CMD_ClearVote, "clearvote", "voteclear", "cv");
             // Admin
             bot.RegisterCommand(coreCommands.CMD_Restart, "restart");
             bot.RegisterCommand(adminCommands.CMD_CallVote, "callvote");
             bot.RegisterCommand(adminCommands.CMD_EndVote, "endvote");
             bot.RegisterCommand(adminCommands.CMD_VoteStatus, "votestatus");
             bot.Client.Ready += () =>
             {
                 bot.Client.SetGameAsync("With the balance of power in this world.").Wait();
                 return(Task.CompletedTask);
             };
         },
         ShouldPayAttentionToMessage = (message) =>
         {
             //return message.Channel is IPrivateChannel || IsAdmin(message.Author);
             return(true);
         }
     });
 }
Exemplo n.º 3
0
        /// <summary>Checks the logon cookie. If by using the logon cookie's packaged details we manage to log in, redirects back to default.</summary>
        protected void LogonCheck()
        {
            HttpCookie UMSWebCreds = Request.Cookies.Get("UMSWEBCREDS");

            if (UMSWebCreds != null)
            {
                if (UMSWebCreds.Value == ":")
                {
                    return;
                }
                String ID  = UMSWebCreds.Value.Split(':')[0];
                String PIN = UMSWebCreds.Value.Split(':')[1];

                //Check ID
                if (ID == null || ID.Length < 5)
                {
                    NotificationSub(Color.Pink, "Invalid ID"); Response.Cookies.Remove("UMSWEBCREDS"); return;
                }

                //Check Pin
                if (PIN == null || PIN.Length < 4)
                {
                    NotificationSub(Color.Pink, "Invalid PIN"); Response.Cookies.Remove("UMSWEBCREDS"); return;
                }

                //Setup Login Result
                string LoginResult;

                //Try to login, and if there's any exception, halt the process.
                try { LoginResult = CoreCommands.CheckUser(ID, PIN); }
                catch (Exception E) { NotificationSub(Color.Pink, E.Message); Response.Cookies.Remove("UMSWEBCREDS"); return; }

                //If it's 3, that means we logged in.
                if (LoginResult == "3")
                {
                    Response.Redirect("~/Default"); return;
                }

                NotificationSub(Color.Pink, "Username or Password Incorrect");
                Response.Cookies.Remove("UMSWEBCREDS");
            }
        }
Exemplo n.º 4
0
        public override void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            base.Init(context, parseNode);

            List <Method> ScopeFuncs = UOSLBase.GetFuncs(context);

            CoreCommands.LoadCoreCommands(context);

            LanguageOption Options = context.GetOptions();

            bool canLoadInherit = true;

            foreach (ParseTreeNode cnode in parseNode.ChildNodes)
            {
                ScopedNode toAdd = null;

                if (cnode.AstNode is InheritsNode)
                {
                    if (canLoadInherit)
                    {
                        toAdd = (ScopedNode)cnode.AstNode;
                        InheritsNode iNode = (InheritsNode)cnode.AstNode;
                        if (Depends.ContainsKey(iNode.Filename))
                        {
                            context.AddParserMessage(ParserErrorLevel.Error, cnode.Span, "File {0} is already loaded in this inheritance chain, cannot reload.", iNode.Filename);
                        }
                        else
                        {
                            m_grammar.LoadFile(iNode.Filename, this, context, Depends);
                        }
                    }
                    else
                    {
                        context.AddParserMessage(ParserErrorLevel.Error, cnode.Span, "Inherits declaration(s) must appear first in the file, may not be made after other declarations.");
                    }
                }
                else
                {
                    canLoadInherit = false;

                    if (cnode.AstNode is EventDefNode)
                    {
                        toAdd = (EventDefNode)cnode.AstNode;
                    }
                    else if (cnode.AstNode is UoCoreFunctionNode)
                    {
                        CoreCommands.Funcs.Add(new Method((FunctionProtoNode)cnode.AstNode, context));
                    }
                    else if (cnode.AstNode is FunctionDefNode)
                    {
                        toAdd = (FunctionDefNode)cnode.AstNode;

                        Method found;
                        string name = ((FunctionDefNode)toAdd).NameString;

                        if (ScopeFuncs != null && (found = ScopeFuncs.FirstOrDefault(func => func.Name == name)) != null && found.DefNode == null)
                        {
                            found.Define((FunctionDefNode)toAdd, context);
                        }
                        else
                        {
                            UOSLBase.AddFunc(new Method((FunctionDefNode)toAdd, context), context);
                        }
                    }
                    else if (cnode.AstNode is FunctionProtoNode)
                    {
                        toAdd = (FunctionProtoNode)cnode.AstNode;
                        UOSLBase.AddFunc(new Method((FunctionProtoNode)toAdd, context), context);
                    }
                    else if (cnode.AstNode is ConstantDeclarationNode)
                    {
                        ConstantDeclarationNode constnode = (ConstantDeclarationNode)cnode.AstNode;
                        toAdd = constnode;
                    }
                    else if (cnode.AstNode is MemberDeclarationNode)
                    {
                        toAdd = (ScopedNode)cnode.AstNode;
                        if (((MemberDeclarationNode)cnode.AstNode).Assign != null)
                        {
                            context.AddParserMessage(ParserErrorLevel.Warning, ((MemberDeclarationNode)cnode.AstNode).Assign.Span, "Member assignments in Declarations are not respected.", ((MemberDeclarationNode)cnode.AstNode).Declaration.Term.Name);
                        }
                        UOSLBase.AddMember(new Field((MemberDeclarationNode)cnode.AstNode, context), context); // global scope?
                    }
                    else if (cnode.AstNode is DeclarationNode)
                    {
                        toAdd = (DeclarationNode)cnode.AstNode;
                        AddVar(new Field((DeclarationNode)toAdd, context), context);
                    }
                }

                if (toAdd != null)
                {
                    ChildNodes.Add(toAdd);
                    toAdd.Parent = this;
                }
            }
        }