示例#1
0
 public void RequestChannelOpListAndQueueFurtherRequest(UserGeneratedCommand command)
 {
     WaitingChannelOpRequests.Add(command);
     MessageQueue.AddMessage(BotMessageFactory.NewMessage(BotMessageFactory.COL, new COLclient()
     {
         channel = command.channel
     }));
 }
示例#2
0
        public void RunChatBotCommand(UserGeneratedCommand command)
        {
            ChatBotCommand c = BotCommands.FirstOrDefault(a => a.Name == command.commandName);

            if (c == null)
            {
                return;
            }

            string[] terms = Utils.LowercaseStrings(command.rawTerms);
            terms         = Utils.FixComparators(terms);
            command.terms = terms;

            object lockObject       = GetObjectToLock(c.LockCategory);
            bool   characterIsAdmin = Utils.IsCharacterAdmin(Bot.AccountSettings.AdminCharacters, command.characterName);

            if (MessageCameFromChannel(command.channel) || !c.RequireChannel)
            {
                if (characterIsAdmin || !c.RequireBotAdmin)
                {
                    if (command.ops == null && c.RequireChannelAdmin && !characterIsAdmin)
                    {
                        Bot.RequestChannelOpListAndQueueFurtherRequest(command);// command.channel, command.characterName, command.rawTerms, terms, command.commandName);
                    }
                    else if ((!c.RequireChannelAdmin) || characterIsAdmin || (command.ops != null && command.ops.Contains(command.characterName)))
                    {
                        if (lockObject != null)
                        {
                            lock (lockObject)
                            {
                                c.Run(Bot, this, command.rawTerms, terms, command.characterName, command.channel, command);
                            }
                        }
                        else
                        {
                            c.Run(Bot, this, command.rawTerms, terms, command.characterName, command.channel, command);
                        }
                    }
                    else
                    {
                        Bot.SendMessageInChannel(Utils.GetCharacterUserTags(command.characterName) + ", you need to be a channel op to use this command (" + command.commandName + ").", command.channel);
                    }
                }
                else
                {
                    Bot.SendMessageInChannel("You do not have authorization to complete this command.", command.channel);
                }
            }
        }
示例#3
0
        public void OnMessage(string data)
        {
            string[] pieces = data.Split(' ');
            if (pieces == null || pieces.Length < 1)
            {
                Console.WriteLine("Error OnMessage, data did not parse correctly.");
                return;
            }
            string messageType = pieces[0];

            string trimmedChatCommand = data.Substring(3).Trim();

            switch (messageType)
            {
            case "NLN":     //a user connected
            case "STA":     //status change for character
            case "FLN":
                break;

            case "RLL":     //a user generated /roll using FChat's roll
                break;

            case "ICH":     //initial channel users
            case "LIS":     //all online characters, gender, status
                break;

            case "COL":     //sent in response to join channel
                COLserver colinfo = JsonConvert.DeserializeObject <COLserver>(trimmedChatCommand);

                Console.WriteLine("Recieved: " + (data.Length > 300 ? data.Substring(0, 300) : data));
                UserGeneratedCommand req = WaitingChannelOpRequests.FirstOrDefault(b => b.channel == colinfo.channel);

                if (req != null)
                {
                    Console.WriteLine("channelops returned COL, channel ops returned");
                    req.ops = colinfo.oplist;
                }
                else
                {
                    ChannelsJoined.Add(colinfo.channel);
                }
                break;

            case "JCH":     //someone joined a channel the bot is in
                JCHserver jchInfo = JsonConvert.DeserializeObject <JCHserver>(trimmedChatCommand);

                ChannelSettings s = GetChannelSettings(jchInfo.channel);

                if (s.GreetNewUsers)
                {
                    SendMessageInChannel("Welcome to the channel, " + Utils.GetCharacterUserTags(jchInfo.character.identity) + "!", jchInfo.channel);
                }
                break;

            case "LCH":    //someone left a channel the bot is in
                break;

            case "PIN":     //ping from server. reply with ping
                MessageQueue.AddMessage(new BotMessage()
                {
                    MessageDataFormat = null, messageType = "PIN"
                });
                break;

            case "PRI":     //private message from a user
                PRICmd msgContentPri = JsonConvert.DeserializeObject <PRICmd>(trimmedChatCommand);
                InterpretChatCommand(new MSGserver()
                {
                    character = msgContentPri.character, message = msgContentPri.message, channel = null
                });
                break;

            case "MSG":     //message sent in channel
                MSGserver msgContent = JsonConvert.DeserializeObject <MSGserver>(trimmedChatCommand);
                InterpretChatCommand(msgContent);
                break;

            default:
                Console.WriteLine("Recieved: " + (data.Length > 300? data.Substring(0, 300) : data));
                break;
            }
        }