コード例 #1
0
ファイル: PluginPlugin.cs プロジェクト: JacobMisirian/JacoBot
 public string Main(IRCMessage message)
 {
     string[] parts = message.Body.Split(' ');
     if (parts.Length < 2)
         return "Incorrect arguments for PluginPlugin!";
     switch (parts[1].ToLower())
     {
         case "list":
             StringBuilder sb = new StringBuilder();
             foreach (KeyValuePair<string, IPlugin> entry in MainClass.MessageHandler.Plugins)
                 sb.Append(entry.Key + " ");
             return "Plugins: " + sb.ToString();
         case "load":
             if (parts.Length < 3)
                 return "Incorrect arguments for load!";
             if (!File.Exists(parts[2] + ".dll"))
                 return "Unknown plugin " + parts[2];
             if (MainClass.MessageHandler.Plugins.ContainsKey(parts[2]))
                 return "Plugin " + parts[2] + " is already loaded!";
             MainClass.MessageHandler.LoadPlugins(parts[2] + ".dll");
             return "Plugin loaded";
         case "unload":
             if (parts.Length < 3)
                 return "Incorrect arguments for unload!";
             if (!File.Exists(parts[2] + ".dll"))
                 return "Unknown plugin " + parts[2];
             if (!MainClass.MessageHandler.Plugins.ContainsKey(parts[2]))
                 return "Plugin " + parts[2] + " is already unloaded!";
             MainClass.MessageHandler.Plugins.Remove(parts[2]);
             return "Plugin unloaded";
         default:
             return "First argument must be load, unload, or list!";
     }
 }
コード例 #2
0
ファイル: PluginPlugin.cs プロジェクト: JacobMisirian/JacoBot
 public bool RequiresAdmin(IRCMessage message)
 {
     string[] parts = message.Body.Split(' ');
     if (parts.Length > 1)
         return (parts[1].ToLower() == "list") ? false : true;
     return false;
 }
コード例 #3
0
ファイル: NotePlugin.cs プロジェクト: JacobMisirian/JacoBot
 public string Main(IRCMessage message)
 {
     string[] parts = message.Body.Split(' ');
     if (parts.Length < 2)
         return "Incorrect arguments for NotePlugin!";
     switch (parts[1].ToLower())
     {
         case "check":
             if (Messages.ContainsKey(message.Sender))
                 return Messages[message.Sender];
             return "No new messages";
         case "send":
             if (parts.Length < 4)
                 return "Incorrect arguments for send!";
             string temp = "";
             if (Messages.ContainsKey(parts[2]))
             {
                 temp = Messages[parts[2]];
                 Messages.Remove(parts[2]);
             }
             Messages.Add(parts[2], message.Body.Substring((parts[0] + parts[1] + parts[2]).Length + 3) + " -" + message.Sender);
             MainClass.IRCClient.SendPRIVMSG("You have a note. Use !note check to check it.", parts[2]);
             return "Message sent";
         default:
             return "First argument must be check or send!";
     }
 }
コード例 #4
0
ファイル: RepPlugin.cs プロジェクト: JacobMisirian/JacoBot
 public string Main(IRCMessage message)
 {
     string[] parts = message.Body.Split(' ');
     if (parts.Length < 3)
         return "Incorrect arguments for RepPlugin!";
     int temp = 0;
     switch (parts[1])
     {
         case "give":
             if (!Reputation.ContainsKey(parts[2]))
                 Reputation.Add(parts[2], 0);
             temp = Reputation[parts[2]];
             Reputation.Remove(parts[2]);
             Reputation.Add(parts[2], temp + 1);
             return parts[2] + " was given one rep by " + message.Sender;
         case "take":
             if (!Reputation.ContainsKey(parts[2]))
                 Reputation.Add(parts[2], 0);
             temp = Reputation[parts[2]];
             Reputation.Remove(parts[2]);
             Reputation.Add(parts[2], temp - 1);
             return parts[2] + " had one rep taken by " + message.Sender;
         case "check":
             if (!Reputation.ContainsKey(parts[2]))
                 Reputation.Add(parts[2], 0);
             return parts[2] + " has " + Reputation[parts[2]] + " rep";
         default:
             return "First argument must be give, take, or check!";
     }
 }
コード例 #5
0
ファイル: HelpPlugin.cs プロジェクト: JacobMisirian/JacoBot
 public string Main(IRCMessage message)
 {
     string[] parts = message.Body.Split(' ');
     if (parts.Length < 2)
         return Help;
     foreach (KeyValuePair<string, IPlugin> entry in MainClass.MessageHandler.Plugins)
         if (entry.Key.ToLower() == parts[1].ToLower())
             return entry.Value.Help;
     return parts[1] + " is not a loaded plugin!";
 }
コード例 #6
0
 public string Handle(IRCMessage message)
 {
     if (!(message.Type == IRCMessageType.PRIVMSG))
         return "";
     foreach (KeyValuePair<string, IPlugin> entry in Plugins)
         if (entry.Value.CanRun(message))
         if (entry.Value.RequiresAdmin(message) && !(AdminUsers.Contains(message.Sender)))
             return "You don't have permission to do that, " + message.Sender + "!";
         else
             return entry.Value.Main(message);
     return "";
 }
コード例 #7
0
 public string Main(IRCMessage message)
 {
     string[] parts = message.Body.Split(' ');
     if (parts.Length < 3)
         return "Incorrect arguments for ChannelPlugin!";
     switch (parts[1].ToLower())
     {
         case "join":
             MainClass.IRCClient.SendRawMessage("JOIN " + parts[2]);
             return "Joined channel";
         case "leave":
             MainClass.IRCClient.SendRawMessage("PART " + parts[2]);
             return "Left channel";
         default:
             return "First argument must be join or leave!";
     }
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: JacobMisirian/JacoBot
 public static void IRCClient_OnMessageRecieved(object sender, MessageRecievedEventArgs e)
 {
     IRCMessage message = IRCMessage.Parse(e.RawMessage);
     if (message.Type == IRCMessageType.PRIVMSG)
     if (!message.Channel.Contains("#"))
         message = new IRCMessage(IRCMessageType.PRIVMSG, message.Sender, message.Sender, message.Body, message.RawMessage);
     try
     {
         MainClass.IRCClient.SendPRIVMSG(MainClass.MessageHandler.Handle(message), message.Channel, 1000);
     }
     catch (Exception ex)
     {
         MainClass.IRCClient.SendPRIVMSG(ex.Message, message.Channel, 2000);
     }
     finally
     {
     }
 }
コード例 #9
0
ファイル: AdminPlugin.cs プロジェクト: JacobMisirian/JacoBot
 public string Main(IRCMessage message)
 {
     string[] parts = message.Body.Split(' ');
     if (parts.Length < 3)
         return "Incorrect arguments for AdminPlugin!";
     switch (parts[1].ToLower())
     {
         case "take":
             if (!MainClass.MessageHandler.AdminUsers.Contains(parts[2]))
                 return parts[2] + " is not an admin!";
             MainClass.MessageHandler.AdminUsers.Remove(parts[2]);
             return parts[2] + " has had their admin taken";
         case "give":
             if (MainClass.MessageHandler.AdminUsers.Contains(parts[2]))
                 return parts[2] + " is already an admin!";
             MainClass.MessageHandler.AdminUsers.Add(parts[2]);
             return parts[2] + " has been made an admin";
         default:
             return "First argument must be give or take!";
     }
 }
コード例 #10
0
 public bool RequiresAdmin(IRCMessage message)
 {
     return true;
 }
コード例 #11
0
 public bool CanRun(IRCMessage message)
 {
     return (message.Body.StartsWith("!channel")) ? true : false;
 }
コード例 #12
0
        public string Main(IRCMessage message)
        {
            string[] parts = message.Body.Split(' ');
            if (parts.Length < 2)
                return "Incorrect arguments for HassiumPlugin!";
            if (parts[1].ToLower() == "limit")
            {
                if (parts.Length < 3)
                    return "Incorrect arguments for limit!";
                try
                {
                    maxCharLength = Convert.ToInt32(parts[2]);
                    return "Limit changed";
                }
                catch
                {
                    return "Second argument must be an integer!";
                }
            }
            else if (parts[1].ToLower() == "time")
            {
                if (parts.Length < 3)
                    return "Incorrect arguments for time!";
                try
                {
                    maxExecutionTime = Convert.ToInt32(parts[2]);
                    return "Time changed";
                }
                catch
                {
                    return "Second argument must be an integer!";
                }
            }

            StringBuilder ret = new StringBuilder();
            string source = message.Body.Substring(message.Body.IndexOf(" "));
            File.WriteAllText("file.has", source);

            var proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "/usr/bin/Hassium.exe",
                    Arguments = "-s file.has",
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow = true
                }
            };

            proc.Start();

            Thread.Sleep(maxExecutionTime);

            try
            {
                proc.Kill();
            }
            catch
            {
            }

            while (!proc.StandardOutput.EndOfStream)
                ret.Append(proc.StandardOutput.ReadLine());

            string res = ret.ToString();
            return (res.Length > maxCharLength) ? res.Substring(0, maxCharLength) : res;
        }
コード例 #13
0
 public bool CanRun(IRCMessage message)
 {
     return message.Body.ToLowerInvariant().Contains("dhillon") || message.Sender.ToLowerInvariant().Contains("dhillon");
 }
コード例 #14
0
 public string Main(IRCMessage message)
 {
     return responses [rng.Next (0, responses.Length)];
 }
コード例 #15
0
ファイル: QuitPlugin.cs プロジェクト: JacobMisirian/JacoBot
 public string Main(IRCMessage message)
 {
     Environment.Exit(0);
     return "";
 }
コード例 #16
0
ファイル: ThanksPlugin.cs プロジェクト: JacobMisirian/JacoBot
 public string Main(IRCMessage message)
 {
     return "Thanks, Donald Trump!";
 }
コード例 #17
0
ファイル: ThanksPlugin.cs プロジェクト: JacobMisirian/JacoBot
 public bool CanRun(IRCMessage message)
 {
     return (message.Body.ToLower().Contains("thank")) ? true : false;
 }