Advertisement
PsyOps

ChatBridge

May 6th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using BattleCore;
  7. using BattleCore.Events;
  8. using BattleCorePsyOps;
  9. using System.Timers;
  10.  
  11. namespace PsyModules
  12. {
  13.     // Add the attribute and the base class
  14.     [Behavior("ChatBridge", "true", "0.01", "PsyOps", "A cross biller chat bridge.")]
  15.     public class ChatBridge:BotEventListener
  16.     {
  17.         public ChatBridge()
  18.         {
  19.             RegisterTimedEvent("MainTimer", 10, updateMainTimer);
  20.         }
  21.  
  22.         string ChatLoginCommand = "?chat=BattleDev,Battle,Alpha,specrpg,";
  23.         bool Initialized = false;
  24.         // Custom module to help with chatevents mainly
  25.         ShortChat msg = new ShortChat();
  26.         // Stores botname and arena
  27.         string BotName, Arena = "";
  28.  
  29.         // --------------------------------------------------------  SS GAME EVENTS //
  30.         // ------------------------------------------------------------------------//
  31.         // Monitor all incoming chat events
  32.         public void MonitorChatEvents(object sender, ChatEvent c)
  33.         {
  34.             // Core sends each bot a pm with its own info 500ms after startup
  35.             // I use it to initialize bot
  36.             if (c.ChatType == ChatTypes.Private && c.Message.StartsWith("@BotInfo@"))
  37.                 // Initialize everything needed to get bot started
  38.                 InitializeBot(c.Message.Split(':')[1], c.Message.Split(':')[2]);
  39.             else if (c.ChatType == ChatTypes.Arena && c.Message.StartsWith("This arena is Continuum-only. Please get Continuum client"))
  40.             {
  41.                 DateTime time = DateTime.Now;
  42.  
  43.                 if (!Initialized)
  44.                 {
  45.                     Game(msg.pub(ChatLoginCommand));
  46.                     Game(msg.arena("Login Detected! - " + time.ToString(" H:mm:ss ")));
  47.                 }
  48.                 else
  49.                 {
  50.                     Game(msg.pub(ChatLoginCommand));
  51.                     Game(msg.arena("Bot recovered from a crash! -" + time.ToString(" H:mm:ss ")));
  52.                 }
  53.             }
  54.             else if (c.ChatType == ChatTypes.Channel)
  55.             {
  56.                 if (c.PlayerName == null) return;
  57.  
  58.                 if (c.PlayerName.Length <= 0)
  59.                 {
  60.                     c.PlayerName = BotName;
  61.                     c.PlayerId = ushort.Parse(c.Message.Substring(0, c.Message.IndexOf(':')));
  62.                     SendCoreEvent(c);
  63.                 }
  64.                 else if (c.PlayerName != BotName)
  65.                 {
  66.                     msg.FormatMessage(c);
  67.                     c.Message = "<SZ> "+ c.PlayerName+ "> " + c.Message;
  68.                     msg.SCChanMessage((byte)c.PlayerId, c.Message);
  69.                     //Game(msg.chan((byte)c.PlayerId,c.Message));
  70.                 }
  71.             }
  72.         }
  73.  
  74.         // Initialize bot for first time
  75.         public void InitializeBot(string BotName, string Arena)
  76.         {
  77.             this.BotName = BotName;
  78.             this.Arena = Arena;
  79.  
  80.             // debug mode set to true
  81.             msg.DebugMode = true;
  82.             // make sure spam control is on for module
  83.             msg.SpamControl = true;
  84.  
  85.             // Turn game on
  86.             Initialized = true;
  87.  
  88.             // update chat with bot initialized msg
  89.             msg.SCChanMessage(1, BotName + " initialized.");
  90.         }
  91.  
  92.         //public void updateMainTimer(object sender, ElapsedEventArgs e)
  93.         public void updateMainTimer()
  94.         {
  95.             // Check to see if we have any commands in our command chat q
  96.             if (msg.NeedUpdate && Initialized) Game(msg.sendNextBCommand());
  97.         }
  98.  
  99.         public override void Dispose()
  100.         {
  101.             throw new NotImplementedException();
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement