Advertisement
fruffl

fruffi events

Aug 6th, 2011
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Fruffi.Bot.Events
  7. {
  8.     abstract class AbstractEvent
  9.     {
  10.         #region private vars
  11.         private Connect connect;
  12.         #endregion
  13.  
  14.         #region props
  15.         protected Connect Connect
  16.         {
  17.             get { return this.connect; }
  18.             set { this.connect = value; }
  19.         }
  20.         #endregion
  21.        
  22.         #region constructor
  23.         public AbstractEvent(Connect connect) { this.Connect = connect; }
  24.         #endregion  
  25.     }
  26.     abstract class AbstractEventsOwnerUser : AbstractEvent
  27.     {
  28.         #region constructor
  29.         public AbstractEventsOwnerUser(Connect connect) : base(connect) { }
  30.         #endregion  
  31.  
  32.         abstract public void Join(string channel, string user);
  33.         abstract public void Part(string channel, string user);
  34.         abstract public void Mode(string channel, string user, string mode);
  35.         abstract public void Kick(string channel, string by, string user, string message);
  36.         abstract public void Nick(string user, string newnick);
  37.         abstract public void Quit(string user, string message);
  38.         abstract public void Query(string user, string message);
  39.         abstract public void Inv(string channel, string user);
  40.     }
  41.     abstract class AbstractEventsChannel : AbstractEvent
  42.     {
  43.         #region constructor
  44.         public AbstractEventsChannel(Connect connect) : base(connect) { }
  45.         #endregion  
  46.  
  47.         abstract public void Topic(string channel, string topic);
  48.         abstract public void TopicOwner(string channel, string user, string date);
  49.         abstract public void Nameslist(string channel, string names);
  50.         abstract public void Priv(string channel, string user, string message, bool is_owner);
  51.     }
  52. }
  53.  
  54. ----------------------------
  55.  
  56. using System;
  57. using System.Collections.Generic;
  58. using System.Linq;
  59. using System.Text;
  60. using Fruffi.Bot.Commands;
  61.  
  62. namespace Fruffi.Bot.Events
  63. {
  64.     class EventsUser : AbstractEventsOwnerUser
  65.     {
  66.         #region constructor
  67.         public EventsUser(Connect connect) : base(connect) { }
  68.         #endregion  
  69.  
  70.         public override void Join(string channel, string user)
  71.         {
  72.             this.Connect.write(this.Connect.Cmd.action(channel, "begrüßt " + user));
  73.         }
  74.         public override void Part(string channel, string user) { Console.WriteLine(channel + ": " + user + " left"); }
  75.         public override void Mode(string channel, string user, string mode) { Console.WriteLine(channel + ": " + user + " mode " + mode); }
  76.         public override void Kick(string channel, string by, string user, string message) { Console.WriteLine(channel + ": " + user + " kicked by " + by + ": " + message); }
  77.         public override void Nick(string user, string newnick) { }
  78.         public override void Quit(string user, string message) { }
  79.         public override void Query(string user, string message)
  80.         {
  81.             if (this.Connect.Helpers.find(user, "spamscanner"))
  82.                 return;
  83.  
  84.             if (this.Connect.Helpers.find(user, "global"))
  85.                 return;
  86.  
  87.             if (this.Connect.Helpers.find(user, "chanserv"))
  88.                 return;
  89.  
  90.             if (this.Connect.Helpers.find(user, "nickserv"))
  91.                 return;
  92.            
  93.             UserCommand u = new UserCommand(this.Connect, message);
  94.             if (u.query(user))
  95.                 this.Connect.write(u.Response);
  96.         }
  97.         public override void Inv(string channel, string user) { Console.WriteLine("INVITE: " + channel + " from " + user); }
  98.     }
  99. }
  100.  
  101.  
  102.  
  103. ----------------------------
  104.  
  105. using System;
  106. using System.Collections.Generic;
  107. using System.Linq;
  108. using System.Text;
  109. using Fruffi.Bot.Events;
  110. using Fruffi.Bot.Chan;
  111.  
  112. namespace Fruffi.Bot.Irc
  113. {
  114.     class Parser
  115.     {
  116.         #region private vars
  117.         private EventsUser uevents;
  118.         private EventsChannel cevents;
  119.         private EventsOwner oevents;
  120.         private EventsFruffi fevents;
  121.         private Connect connect;
  122.         #endregion
  123.  
  124.         #region props
  125.         public Connect Connect
  126.         {
  127.             get { return this.connect; }
  128.             set { this.connect = value; }
  129.         }
  130.         public EventsUser UserEvents
  131.         {
  132.             get { return this.uevents; }
  133.             set { this.uevents = value; }
  134.         }
  135.         public EventsChannel ChannelEvents
  136.         {
  137.             get { return this.cevents; }
  138.             set { this.cevents = value; }
  139.         }
  140.         public EventsOwner OwnerEvents
  141.         {
  142.             get { return this.oevents; }
  143.             set { this.oevents = value; }
  144.         }
  145.         public EventsFruffi FruffiEvents
  146.         {
  147.             get { return this.fevents; }
  148.             set { this.fevents = value; }
  149.         }
  150.         #endregion
  151.        
  152.         #region constructor
  153.         public Parser(Connect connect)
  154.         {
  155.             this.Connect = connect;
  156.             this.UserEvents = new EventsUser(this.Connect);
  157.             this.ChannelEvents = new EventsChannel(this.Connect);
  158.             this.OwnerEvents = new EventsOwner(this.Connect);
  159.             this.FruffiEvents = new EventsFruffi(this.Connect);
  160.         }
  161.         #endregion  
  162.  
  163.        
  164.         #region channel
  165.         public void Topic(string[] c)
  166.         {
  167.             this.ChannelEvents.Topic(this.Connect.Helpers.RemoveColon(c[3]), this.Connect.Helpers.ArrayToString(c, 4));
  168.         }
  169.         public void TopicOwner(string[] c)
  170.         {
  171.             this.ChannelEvents.TopicOwner(c[3], this.Connect.Helpers.Nick(c[4]), c[5]);
  172.         }
  173.         public void Nameslist(string[] c)
  174.         {
  175.             string b = this.Connect.Helpers.RemoveColon(c[4]);
  176.             string d = this.Connect.Helpers.ArrayToString(c, 5);
  177.             this.ChannelEvents.Nameslist(b, d);
  178.  
  179.             Channel t = this.Connect.Channels.get(b);
  180.             string[] a = d.Split(' ');
  181.             for (int i = 0; i < a.Length; i++)
  182.                 t.add(a[i]);
  183.         }
  184.         #endregion
  185.  
  186.         #region user
  187.         public void Join(string[] c)
  188.         {
  189.             string n = this.Connect.Helpers.Nick(c[0]);
  190.             string t = this.Connect.Helpers.RemoveColon(c[2]);
  191.  
  192.             Channel b = this.Connect.Channels.get(t);
  193.             b.add(n);
  194.  
  195.             if (n == this.Connect.Owner.Nick)
  196.             {
  197.                 this.OwnerEvents.Join(t, n);
  198.                 return;
  199.             }
  200.             else if (n == this.Connect.Config.Nick)
  201.             {
  202.                 if(this.Connect.Channels == null)
  203.                     this.Connect.Channels = new ChannelList();
  204.  
  205.                 this.Connect.Channels.get(t);
  206.  
  207.                 this.FruffiEvents.Join(t, n);
  208.                 return;
  209.             }
  210.  
  211.             if (!this.Connect.Storage.Ignore.Exists(n))
  212.                 this.UserEvents.Join(t, n);
  213.         }
  214.         public void Part(string[] c)
  215.         {
  216.             string n = this.Connect.Helpers.Nick(c[0]);
  217.             string t = this.Connect.Helpers.RemoveColon(c[2]);
  218.  
  219.             Channel b = this.Connect.Channels.get(t);
  220.             b.del(n);
  221.  
  222.             if (n == this.Connect.Owner.Nick)
  223.             {
  224.                 this.OwnerEvents.Part(t, n);
  225.                 return;
  226.             }
  227.             if (n == this.Connect.Config.Nick)
  228.             {
  229.                 this.Connect.Channels.del(t);
  230.             }
  231.  
  232.             if (!this.Connect.Storage.Ignore.Exists(n))
  233.                 this.UserEvents.Part(t, n);
  234.         }
  235.         public void Mode(string[] c)
  236.         {
  237.             string n = this.Connect.Helpers.Nick(c[0]);
  238.             string t = this.Connect.Helpers.RemoveColon(c[2]);
  239.             string m = this.Connect.Helpers.RemoveColon(this.Connect.Helpers.ArrayToString(c, 3));
  240.  
  241.             if (n == this.Connect.Owner.Nick)
  242.             {
  243.                 this.OwnerEvents.Mode(t, n, m);
  244.                 return;
  245.             }
  246.             else if (n == this.Connect.Config.Nick)
  247.             {
  248.                 this.FruffiEvents.Mode(t, n, m);
  249.                 return;
  250.             }
  251.  
  252.             if (!this.Connect.Storage.Ignore.Exists(n))
  253.                 this.UserEvents.Mode(t, n, m);
  254.         }
  255.         public void Kick(string[] c)
  256.         {
  257.             string n = this.Connect.Helpers.Nick(c[0]);
  258.             string t = this.Connect.Helpers.RemoveColon(c[2]);
  259.             string m = this.Connect.Helpers.RemoveColon(this.Connect.Helpers.ArrayToString(c, 4));
  260.  
  261.             Channel b = this.Connect.Channels.get(t);
  262.             b.del(n);
  263.  
  264.             if (n == this.Connect.Owner.Nick)
  265.             {
  266.                 this.OwnerEvents.Kick(t, n, c[3], m);
  267.                 return;
  268.             }
  269.  
  270.             if (!this.Connect.Storage.Ignore.Exists(n))
  271.                 this.UserEvents.Kick(t, n, c[3], m);
  272.         }
  273.         public void Nick(string[] c)
  274.         {
  275.             string n = this.Connect.Helpers.Nick(c[0]);
  276.             string k = this.Connect.Helpers.RemoveColon(c[2]);
  277.  
  278.             this.Connect.Channels.nick(n, k);
  279.  
  280.             if (n == this.Connect.Owner.Nick)
  281.             {
  282.                 Console.WriteLine("OWNER changed nick to " + k);
  283.                 this.Connect.Owner.Nick = k;
  284.                 this.OwnerEvents.Nick(n, k);
  285.                 return;
  286.             }
  287.             else if (n == this.Connect.Config.Nick)
  288.             {
  289.                 Console.WriteLine("YOU changed nick to " + k);
  290.                 this.Connect.Config.Nick = k;
  291.                 this.FruffiEvents.Nick(n, k);
  292.                 return;
  293.             }
  294.  
  295.             if (!this.Connect.Storage.Ignore.Exists(n))
  296.                 this.UserEvents.Nick(n, k);
  297.         }
  298.         public void Quit(string[] c)
  299.         {
  300.             string n = this.Connect.Helpers.Nick(c[0]);
  301.             string m = this.Connect.Helpers.RemoveColon(this.Connect.Helpers.ArrayToString(c, 2));
  302.  
  303.             this.Connect.Channels.kill(n);
  304.  
  305.             if (n == this.Connect.Owner.Nick)
  306.             {
  307.                 this.OwnerEvents.Quit(n, m);
  308.                 return;
  309.             }
  310.  
  311.             if (!this.Connect.Storage.Ignore.Exists(n))
  312.                 this.UserEvents.Quit(n, m);
  313.         }
  314.         public void Priv(string[] c)
  315.         {
  316.             string n = this.Connect.Helpers.Nick(c[0]);
  317.             string t = this.Connect.Helpers.RemoveColon(c[2]);
  318.             string m = this.Connect.Helpers.RemoveColon(this.Connect.Helpers.ArrayToString(c, 3));
  319.  
  320.             if (t.Substring(0, 1) != "#")
  321.             {
  322.                 if (n == this.Connect.Owner.Nick)
  323.                     this.OwnerEvents.Query(n, m);
  324.                 else
  325.                     this.UserEvents.Query(n, m);
  326.                 return;
  327.             }
  328.  
  329.             if (!this.Connect.Storage.Ignore.Exists(n))
  330.                 this.ChannelEvents.Priv(t, n, m, (n == this.Connect.Owner.Nick));
  331.  
  332.             //this.Idler();
  333.         }
  334.         public void Inv(string[] c)
  335.         {
  336.             string n = this.Connect.Helpers.Nick(c[0]);
  337.             string t = this.Connect.Helpers.RemoveColon(c[3]);
  338.  
  339.             if (n == this.Connect.Owner.Nick)
  340.             {
  341.                 this.OwnerEvents.Inv(t, n);
  342.                 return;
  343.             }
  344.  
  345.             if (!this.Connect.Storage.Ignore.Exists(n))
  346.                 this.UserEvents.Inv(t, n);
  347.         }
  348.         #endregion
  349.     }
  350. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement