Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.18 KB | None | 0 0
  1. using Matrix;
  2. using Matrix.Xmpp;
  3. using Matrix.Xmpp.Client;
  4. using Parser;
  5. using PVPNetConnect;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using BotEventArgs;
  12. using EnumConvertExtensions;
  13. using PVPNetConnect.RiotObjects.Platform.Summoner;
  14. using PVPNETExtensions;
  15.  
  16. public class Bot : IDisposable
  17. {
  18. // nested class
  19. public class LeagueRank
  20. {
  21. public LeagueRank(Rank pRank, int pDiv)
  22. {
  23. Ranking = pRank;
  24. Division = pDiv;
  25. }
  26. public Rank Ranking { get; private set; }
  27. public enum Rank
  28. {
  29. Unranked = 0x0,
  30. BRONZE = 0x5,
  31. SILVER = 0xA,
  32. GOLD = 0xF,
  33. PLATINUM = 0x14,
  34. DIAMOND = 0x19,
  35. }
  36. public int Division { get; private set; }
  37. public static bool operator ==(LeagueRank pLeague, LeagueRank pLeague2)
  38. {
  39. return (int)pLeague.Ranking + pLeague.Division == (int)pLeague2.Ranking + pLeague2.Division;
  40. }
  41. public static bool operator !=(LeagueRank pLeague, LeagueRank pLeagu2)
  42. {
  43. return !(pLeague == pLeagu2);
  44. }
  45. public static bool operator <(LeagueRank pLeague, LeagueRank pLeague2)
  46. {
  47. return (int)pLeague.Ranking + (5 - pLeague.Division) < (int)pLeague2.Ranking + (5 - pLeague2.Division);
  48. }
  49. public static bool operator >(LeagueRank pLeague, LeagueRank pLeague2)
  50. {
  51. return (int)pLeague.Ranking + (5 - pLeague.Division) > (int)pLeague2.Ranking + (5 - pLeague2.Division);
  52. }
  53. public static bool operator <=(LeagueRank pLeague, LeagueRank pLeague2)
  54. {
  55. return (pLeague == pLeague2 || pLeague < pLeague2);
  56. }
  57. public static bool operator >=(LeagueRank pLeague, LeagueRank pLeague2)
  58. {
  59. return (pLeague == pLeague2 || pLeague > pLeague2);
  60. }
  61. public static LeagueRank ParseFromString(string pInput)
  62. {
  63. if (!pInput.Contains(' '))
  64. {
  65. return new LeagueRank(Rank.Unranked, 0);
  66. }
  67. else
  68. {
  69. string[] lParts = pInput.Split(' ');
  70. string lFirst = lParts[0];
  71. string lSecond = lParts[1];
  72. if (string.IsNullOrWhiteSpace(lSecond))
  73. return new LeagueRank(Rank.Unranked, 0);
  74. Rank lRank = Rank.Unranked;
  75. switch (lFirst)
  76. {
  77. case "BRONZE":
  78. lRank = Rank.BRONZE;
  79. break;
  80. case "SILVER":
  81. lRank = Rank.SILVER;
  82. break;
  83. case "GOLD":
  84. lRank = Rank.GOLD;
  85. break;
  86. case "PLATINUM":
  87. lRank = Rank.PLATINUM;
  88. break;
  89. case "DIAMOND":
  90. lRank = Rank.DIAMOND;
  91. break;
  92. }
  93. int lVal = 0;
  94. if (lSecond.Length != 2)
  95. {
  96. foreach (var item in lSecond)
  97. {
  98. if (item == 'V')
  99. lVal = 4;
  100. else if (item == 'I')
  101. lVal++;
  102. }
  103. }
  104. else
  105. {
  106. foreach (var item in lSecond)
  107. {
  108. if (item == 'V')
  109. lVal = 5;
  110. else if (item == 'I')
  111. lVal++;
  112. }
  113. }
  114. return new LeagueRank(lRank, lVal);
  115.  
  116. }
  117. }
  118. }
  119. bool disposed = false;
  120. public void Dispose()
  121. {
  122. Dispose(true);
  123. }
  124. public EventHandler Botdisposed;
  125. protected virtual void Dispose(bool disposing)
  126. {
  127.  
  128. if (disposing && !disposed)
  129. {
  130.  
  131.  
  132. using (LoL_AutoAdder.lol_usersEntities lContext = new LoL_AutoAdder.lol_usersEntities())
  133. {
  134. for (var x = actualOnes.Count - 1; x >= 0; x--)
  135. {
  136.  
  137.  
  138.  
  139.  
  140. int lValue = int.Parse(actualOnes[x]);
  141. var lUser = from it in lContext.users
  142. where it.Region == this.WebScraper.LowerRegion
  143. && it.SummonerID.Value == lValue
  144. select it;
  145. try
  146. {
  147. if (lUser.Count() > 0)
  148. {
  149. foreach (var user in lUser)
  150. {
  151.  
  152. user.Scraped = false;
  153.  
  154. }
  155. }
  156. lContext.SaveChanges();
  157. }
  158. catch (System.Reflection.TargetException ey)
  159. {
  160. Console.WriteLine(ey.Message);
  161. }
  162. }
  163.  
  164. }
  165.  
  166. if (Botdisposed != null)
  167. Botdisposed(this, System.EventArgs.Empty);
  168. WebScraper.Logger.LoggedIn = false;
  169. WebScraper.Stop();
  170. WebScraper = null;
  171. if (_chat != null)
  172. _chat.Close();
  173. if (_client != null)
  174. _client.Disconnect();
  175. _chat = null;
  176. _client = null;
  177. _logged_In = false;
  178. }
  179. disposed = true;
  180. }
  181. //Chatclient
  182. private XmppClient _chat = new XmppClient();
  183. public XmppClient Chat
  184. {
  185. get { return _chat; }
  186. }
  187. //Gameclient
  188. private PVPNetConnection _client = new PVPNetConnection();
  189. public PVPNetConnection Client
  190. {
  191. get { return _client; }
  192. }
  193.  
  194. public bool SummSite
  195. {
  196. get { return _lolSumm; }
  197. }
  198.  
  199. private Region _Region;
  200. public Region Region
  201. {
  202. get { return _Region; }
  203. }
  204.  
  205. private bool _acceptFriends = false;
  206. public bool AcceptFriends
  207. {
  208. get { return _acceptFriends; }
  209. set { _acceptFriends = value; }
  210. }
  211.  
  212. //Taking the Username's from lolsummoners
  213. public Scraper WebScraper { get; set; }
  214.  
  215.  
  216.  
  217. //Class to progress the Input
  218. private Tokenizer Token = new Tokenizer();
  219.  
  220. //Serverdomain of every Region
  221. private Dictionary<Region, string> regionDictionary = new Dictionary<Region, string>();
  222. private Dictionary<string, Region> newDict = new Dictionary<string, Region>();
  223. //All Commands
  224. private Dictionary<string, ParamAction> newAction = new Dictionary<string, ParamAction>();
  225. private static ExpressionParser _express;
  226. public event EventHandler<SummonerEventArgs> Game_Start;
  227. public event EventHandler<SummonerEventArgs> Game_End;
  228. public event EventHandler LoginSucceed;
  229. /// <summary>
  230. /// Signature of commands
  231. /// </summary>
  232. /// <param name="pParameter">All parameters of commands</param>
  233. /// <returns></returns>
  234. public delegate Task<string> ParamAction(Jid SummonerJID, params string[] pParameter);
  235.  
  236.  
  237. private bool _logged_In = false;
  238. public bool Logged_In
  239. {
  240. get { return _logged_In; }
  241. set
  242. {
  243. this._logged_In = value;
  244. if (this.WebScraper != null)
  245. this.WebScraper.Logger.LoggedIn = value;
  246. }
  247. }
  248.  
  249. private ParamAction _defaultCommand;
  250.  
  251. /// <summary>
  252. /// Functionpointer to function that shall get executed when no command got matched by the message
  253. /// </summary>
  254. public ParamAction DefaultCommand
  255. {
  256. get { return _defaultCommand; }
  257. set { _defaultCommand = value; }
  258. }
  259. private string _username;
  260. /// <summary>
  261. /// starts the bot
  262. /// </summary>
  263. /// <param name="pUsername">Account name to log in</param>
  264. /// <param name="pPassword">Account password to log in</param>
  265. /// <param name="pRegion">Region to log in</param>
  266. public void Start(string pUsername, string pPassword, Region pRegion)
  267. {
  268. PrepareStart(pUsername, pPassword, pRegion);
  269. Start();
  270. }
  271. public void Start()
  272. {
  273. ChatLogin(this._username, this._password, this._Region);
  274. if (_lolSumm) ClientLogin(this._username, this._password, this._Region);
  275. }
  276. public void PrepareStart(string pUsername, string pPassword, Region pRegion)
  277. {
  278. _Region = pRegion;
  279. _username = pUsername;
  280. _password = pPassword;
  281. }
  282. private readonly bool _lolSumm;
  283. public void Start(string pUsername, string pPassword, string pRegion)
  284. {
  285. pRegion = pRegion.Trim('\r').ToLower();
  286. pUsername = pUsername.Trim('\r');
  287. pPassword = pPassword.Trim('\r');
  288. if (!newDict.ContainsKey(pRegion))
  289. return;
  290.  
  291. WebScraper.Region = pRegion;
  292. WebScraper.Logger.Username = pUsername;
  293. Start(pUsername, pPassword, newDict[pRegion]);
  294. }
  295. private Random _random = new Random(DateTime.Now.Millisecond);
  296. private bool isFullReq = false;
  297. public bool FullRequest { get { return isFullReq; } }
  298. private List<string> users = new List<string>();
  299. private void Users_Found(object sender, UserFoundEventArgs e)
  300. {
  301.  
  302. if (this.disposed)
  303. {
  304. throw new ObjectDisposedException("Disposed");
  305. }
  306. actualOnes = e.Users.ToList();
  307. foreach (var item in e.Users)
  308. {
  309. if (this.disposed)
  310. {
  311.  
  312. return;
  313. }
  314. try
  315. {
  316. if (isFullReq)
  317. {
  318. System.Threading.Thread.Sleep(_waitTime + _max);
  319. }
  320. //while (lSummonerID == "0")
  321. //{
  322. // System.Threading.Thread.Sleep(10000);
  323. // lSummonerID = (await lID).SummonerId.ToString();
  324. //}
  325. var lJid = "sum" + item + "@pvp.net";
  326. this.AddFriend(lJid, false);
  327. users.Add(lJid);
  328. //this.SendMessage(lJid, this.Spamtext);
  329. //this.RemoveFriend(lJid, true);
  330. using (LoL_AutoAdder.lol_usersEntities lContext = new LoL_AutoAdder.lol_usersEntities())
  331. {
  332. var lUser = from it in lContext.users
  333. where it.Region == this.WebScraper.LowerRegion
  334. && it.SummonerID.Value.ToString() == item
  335. select it;
  336. try
  337. {
  338. if (lUser.Count() > 0)
  339. {
  340. foreach (var user in lUser)
  341. {
  342. user.Friendreqest = true;
  343. }
  344. }
  345. lContext.SaveChanges();
  346. }
  347. catch (System.Reflection.TargetException ey)
  348. {
  349. Console.WriteLine(ey.Message);
  350. }
  351. }
  352.  
  353. System.Threading.Thread.Sleep(_random.Next(_min, _max));
  354. actualOnes.Remove(item);
  355. }
  356. catch { }
  357. }
  358.  
  359. //System.Threading.Thread.Sleep(10000);
  360.  
  361. }
  362. private List<string> actualOnes = new List<string>();
  363.  
  364. /// <summary>
  365. /// Adds a new command
  366. /// </summary>
  367. /// <param name="pCommand">Text to execute the command (case insensitive)</param>
  368. /// <param name="pExecution">Functionpointer to function that shall get executed</param>
  369. /// <returns>True if successful otherwise false</returns>
  370. public bool AddCommand(string pCommand, ParamAction pExecution)
  371. {
  372. if (!newAction.ContainsKey(pCommand.ToLower()))
  373. {
  374. newAction.Add(pCommand.ToLower(), pExecution);
  375. return true;
  376. }
  377. return false;
  378. }
  379. private string _password;
  380. /// <summary>
  381. /// Removes a existing command
  382. /// </summary>
  383. /// <param name="pCommand">Command to remove</param>
  384. /// <returns>True if successful otherwise false</returns>
  385. public bool RemoveCommand(string pCommand)
  386. {
  387. if (newAction.ContainsKey(pCommand.ToLower()))
  388. {
  389. newAction.Remove(pCommand.ToLower());
  390. return true;
  391. }
  392. return false;
  393. }
  394. private string _spamText;
  395. public string Spamtext
  396. {
  397. get { return _spamText; }
  398. set
  399. {
  400. _spamText = value;
  401. this.WebScraper.Logger.Message = value;
  402. }
  403. }
  404. private int _min;
  405. private int _max;
  406. private int _waitTime;
  407. public Bot(LeagueRank pMin, LeagueRank pMax, int pMinim, int pMaxim, int pLvlmin, int pLvlmax, string pSpamtext, string pClientVersion, bool pSumm, int pWaitTime, DateTime pDate)
  408. {
  409. From = pMin;
  410. To = pMax;
  411. _min = pMinim;
  412. _max = pMaxim;
  413. Min = pLvlmin;
  414. Max = pLvlmax;
  415. _waitTime = pWaitTime;
  416. _clientVersion = pClientVersion;
  417. regionDictionary.Add(Region.EUW, "euw1");
  418. regionDictionary.Add(Region.EUN, "eun1");
  419. regionDictionary.Add(Region.NA, "na2");
  420. regionDictionary.Add(Region.TR, "tr");
  421. regionDictionary.Add(Region.RU, "ru");
  422. regionDictionary.Add(Region.BR, "br");
  423. regionDictionary.Add(Region.OCE, "oc1");
  424. regionDictionary.Add(Region.KR, "kr");
  425. regionDictionary.Add(Region.LAN, "la1");
  426. regionDictionary.Add(Region.LAS, "la2");
  427. newDict.Add("euw", Region.EUW);
  428. newDict.Add("eune", Region.EUN);
  429. newDict.Add("na", Region.NA);
  430. newDict.Add("tr", Region.TR);
  431. newDict.Add("ru", Region.RU);
  432. newDict.Add("br", Region.BR);
  433. newDict.Add("oce", Region.OCE);
  434. newDict.Add("kr", Region.KR);
  435. newDict.Add("lan", Region.LAN);
  436. newDict.Add("las", Region.LAS);
  437. //to be continued
  438. Client.OnLogin += new PVPNetConnection.OnLoginHandler(Client_OnLogin);
  439. Chat.OnLogin += new EventHandler<Matrix.EventArgs>(Chat_OnLogin);
  440. Chat.OnMessage += new EventHandler<MessageEventArgs>(Chat_OnMessage);
  441. Token.Parsed += new Tokenizer.ParsedEventHandler(Token_Parsed);
  442. Chat.OnPresence += new EventHandler<PresenceEventArgs>(On_Presence);
  443. Client.OnDisconnect += new PVPNetConnection.OnDisconnectHandler(Client_Disconnected);
  444. Chat.OnClose += new EventHandler<Matrix.EventArgs>(Chat_Close);
  445. _lolSumm = pSumm;
  446. WebScraper = new DatabaseScraper(pMin, pMax, 0, pDate);
  447. WebScraper.User_Found += new EventHandler<UserFoundEventArgs>(Users_Found);
  448. Chat.AutoRoster = false;
  449. Client.OnError += new PVPNetConnection.OnErrorHandler(Client_Error);
  450. Chat.OnError += new EventHandler<ExceptionEventArgs>(Chat_Error);
  451. Chat.OnRosterItem += new EventHandler<Matrix.Xmpp.Roster.RosterEventArgs>(Roster_Requested);
  452. Chat.OnRosterEnd += new EventHandler<Matrix.EventArgs>(Roster_End);
  453. this.Spamtext = pSpamtext;
  454. this.DefaultCommand = Message;
  455.  
  456. }
  457. public LeagueRank From { get; private set; }
  458. public LeagueRank To { get; private set; }
  459. private void Chat_Error(object sender, ExceptionEventArgs e)
  460. {
  461. this.Dispose();
  462.  
  463. }
  464. private void Client_Error(object sender, PVPNetConnect.Error e)
  465. {
  466. this.Dispose();
  467. }
  468. static Bot()
  469. {
  470. _express = new ExpressionParser();
  471. }
  472. public static IEnumerable<System.Tuple<string, string, string, Bot>> CreateFromString(string pInput, string pClientVersion, bool pEndsite)
  473. {
  474. return _express.ParseExpression(pInput, pClientVersion, pEndsite);
  475. }
  476. private void Chat_Close(object sender, Matrix.EventArgs e)
  477. {
  478.  
  479.  
  480. this.Dispose();
  481.  
  482. //this._chat = new XmppClient();
  483. //this._client = new PVPNetConnection();
  484. //this.Start(this._username, this._password, this._Region);
  485. }
  486. private void Client_Disconnected(object sender, System.EventArgs e)
  487. {
  488. //this._chat = new XmppClient();
  489. //this._client = new PVPNetConnection();
  490. //this.Start(this._username, this._password, this._Region);
  491. }
  492. /// <summary>
  493. /// Add user to friendlist
  494. /// </summary>
  495. /// <param name="pSummonerID">SummonerJID of User</param>
  496. public void AddFriend(Jid pSummonerID, bool pOut)
  497. {
  498. if (Chat == null)
  499. return;
  500. Chat.Send(createPresence(pOut ? PresenceType.subscribed : PresenceType.subscribe, pSummonerID));
  501. if (!pOut) this.WebScraper.Logger.FriendrequestsSend++;
  502. }
  503.  
  504. private Presence createPresence(PresenceType pType, Jid pSummonerID)
  505. {
  506. var newPresence = new Presence(pType);
  507. newPresence.Priority = 0;
  508. newPresence.To = pSummonerID;
  509. return newPresence;
  510. }
  511.  
  512. /// <summary>
  513. /// Remove friend of friendlist
  514. /// </summary>
  515. /// <param name="pSummonerID">SummonerJID of friend</param>
  516. public void RemoveFriend(Jid pSummonerID, bool pOut)
  517. {
  518. if (Chat != null)
  519. Chat.Send(createPresence(pOut ? PresenceType.unsubscribed : PresenceType.unsubscribe, pSummonerID));
  520. }
  521. private int _acceptedFriends = 0;
  522. private async void On_Presence(object sender, PresenceEventArgs e)
  523. {
  524. if (e.Presence.Error != null && e.Presence.Error.Type == Matrix.Xmpp.Base.ErrorType.wait)
  525. {
  526. if (e.Presence.Error.Text == "max_outgoing_invites")
  527. {
  528. isFullReq = true;
  529. await Task.Delay(_waitTime);
  530. var lList = users.Select((item) => (string)item.Clone()).ToList();
  531. foreach (var item in lList)
  532. {
  533. try
  534. {
  535. //while (lSummonerID == "0")
  536. //{
  537. // System.Threading.Thread.Sleep(10000);
  538. // lSummonerID = (await lID).SummonerId.ToString();
  539. //}
  540. this.RemoveFriend(item, false);
  541. //this.SendMessage(lJid, this.Spamtext);
  542. //this.RemoveFriend(lJid, true);
  543.  
  544.  
  545. await Task.Delay(_random.Next(_min, _max));
  546. }
  547. catch { }
  548. }
  549. users.RemoveAll((elem) => lList.Contains(elem));
  550. isFullReq = false;
  551. }
  552. else
  553. {
  554. using (LoL_AutoAdder.lol_usersEntities lContext = new LoL_AutoAdder.lol_usersEntities())
  555. {
  556. var lUser = from item in lContext.test2
  557. where item.Region == this.WebScraper.LowerRegion
  558. && item.SummonerName == this.Username.ToLower()
  559. select item;
  560. try
  561. {
  562. if (lUser.Count() > 0)
  563. lUser.First().Fullfriendlist = true;
  564. lContext.SaveChanges();
  565. }
  566. catch (System.Reflection.TargetException ey)
  567. {
  568. Console.WriteLine(ey.Message);
  569. }
  570. this.Dispose();
  571. }
  572. }
  573.  
  574.  
  575.  
  576. }
  577. if (e.Presence.Type == PresenceType.subscribe && this.AcceptFriends && !this.disposed)
  578. {
  579. AddFriend(e.Presence.From, true);
  580. if (DefaultCommand != null)
  581. {
  582. DefaultCommand.BeginInvoke(e.Presence.From, new string[] { string.Empty }, async item =>
  583. {
  584. Task<string> lResult = (DefaultCommand.EndInvoke(item));
  585. var Result = await lResult;
  586. SendMessage(e.Presence.From, Result);
  587. RemoveFriend(e.Presence.From, false);
  588. lResult.Dispose();
  589. }, null);
  590. }
  591. }
  592. else if (e.Presence.Type == PresenceType.subscribed && !this.disposed)
  593. {
  594. _acceptedFriends++;
  595. lastAccepted = DateTime.Now;
  596. this.WebScraper.Logger.CountFriends++;
  597. using (LoL_AutoAdder.lol_usersEntities lContext = new LoL_AutoAdder.lol_usersEntities())
  598. {
  599. var lUser = from item in lContext.users
  600. where item.Region == this.WebScraper.LowerRegion
  601. && item.SummonerID.ToString() == e.Presence.From.User
  602. select item;
  603. try
  604. {
  605. if (lUser.Count() > 0)
  606. lUser.First().Accept = true;
  607. lContext.SaveChanges();
  608. }
  609. catch (System.Reflection.TargetException ey)
  610. {
  611. Console.WriteLine(ey.Message);
  612. }
  613. }
  614. if (DefaultCommand != null)
  615. {
  616. DefaultCommand.BeginInvoke(e.Presence.From, new string[] { string.Empty }, async item =>
  617. {
  618. Task<string> lResult = (DefaultCommand.EndInvoke(item));
  619. var Result = await lResult;
  620. SendMessage(e.Presence.From, Result);
  621. RemoveFriend(e.Presence.From, false);
  622. lResult.Dispose();
  623. }, null);
  624. }
  625. }
  626.  
  627. var presenceMessage = e.Presence.ToString();
  628. if (GameStarted(presenceMessage) && e.Presence.Show == Show.dnd && Logged_In && Game_Start != null)
  629. {
  630. Game_Start(sender, new SummonerEventArgs(e.Presence.From));
  631. }
  632. else if (GameEnded(presenceMessage) && e.Presence.Show == Show.chat && Logged_In && Game_End != null)
  633. {
  634. Game_End(sender, new SummonerEventArgs(e.Presence.From));
  635. }
  636.  
  637. }
  638. public string Username { get; private set; }
  639. public int Min { get; private set; }
  640. public int Max { get; private set; }
  641. private DateTime lastAccepted;
  642. private void ChatLogin(string pUsername, string pPassword, Region pRegion)
  643. {
  644. pUsername = pUsername.Trim();
  645. pPassword = pPassword.Trim();
  646. Username = pUsername;
  647. if (!regionDictionary.ContainsKey(pRegion))
  648. throw new ArgumentException("Region not available yet");
  649. if (Chat == null)
  650. return;
  651. Chat.SetUsername(pUsername);
  652. Chat.SetXmppDomain("pvp.net");
  653. Chat.Port = 5223;
  654. Chat.Show = Matrix.Xmpp.Show.chat;
  655. Chat.Password = ("AIR_" + pPassword);
  656. Chat.Resource = "xiff";
  657. Chat.OldStyleSsl = true;
  658. Chat.Hostname = string.Concat("chat.", regionDictionary[pRegion], ".lol.riotgames.com");
  659. Chat.Open();
  660. }
  661.  
  662. public bool GameStarted(string presenceInput)
  663. {
  664. return presenceInput.Contains("gameStatus&gt;inGame&lt;/gameStatus");
  665. }
  666.  
  667. public bool GameEnded(string presenceInput)
  668. {
  669. return presenceInput.Contains("gameStatus&gt;outOfGame&lt;/gameStatus");
  670. }
  671. private string _clientVersion;
  672. private void ClientLogin(string pUsername, string pPassword, Region pRegion)
  673. {
  674. if (Client != null)
  675. Client.Connect(pUsername, pPassword, pRegion, _clientVersion);
  676. }
  677. public void ChangeStatus(int level, int wins, League league, string division)
  678. {
  679. Chat.SendPresence(Show.chat, "<body><profileIcon>508</profileIcon><statusMsg></statusMsg><dropInSpectateGameId>Shopuff</dropInSpectateGameId><featuredGameData>null</featuredGameData><level>" + level + "</level><wins>" + wins + "</wins><leaves>25</leaves><odinWins>148</odinWins><odinLeaves>1</odinLeaves><queueType /><rankedLosses>0</rankedLosses><rankedRating>0</rankedRating><tier>DIAMOND</tier><skinname>Lulu</skinname><gameQueueType>RANKED_SOLO_5x5</gameQueueType><timeStamp>1398886764092</timeStamp><gameStatus>outOfGame</gameStatus><rankedLeagueName></rankedLeagueName><rankedLeagueDivision>" + division + "</rankedLeagueDivision><rankedLeagueTier>" + league.ToStringValue() + "</rankedLeagueTier><rankedLeagueQueue>RANKED_SOLO_5x5</rankedLeagueQueue><rankedWins>" + wins + "</rankedWins></body>", 0);
  680. }
  681. public enum League
  682. {
  683. [StringValue("BRONZE")]
  684. Bronze,
  685. [StringValue("SILVER")]
  686. Silver,
  687. [StringValue("GOLD")]
  688. Gold,
  689. [StringValue("PLATINUM")]
  690. Platin,
  691. [StringValue("DIAMOND")]
  692. Diamond,
  693. [StringValue("CHALLENGER")]
  694. Challenger
  695. }
  696. private void Client_OnLogin(object sender, string username, string ipAddress)
  697. {
  698. //if (!this._lolSumm)
  699. // return;
  700. //Logged_In = true;
  701. //if (LoginSucceed != null)
  702. // LoginSucceed(this, System.EventArgs.Empty);
  703. //Action pAction = WebScraper.GetUserLoop;
  704. //pAction.BeginInvoke(pAction.EndInvoke, null);
  705. //ChangeStatus(69, 1337, League.Diamond, this._spamText);
  706. }
  707. private void Chat_OnLogin(object sender, Matrix.EventArgs e)
  708. {
  709. if (this._lolSumm)
  710. return;
  711. Logged_In = true;
  712. if (LoginSucceed != null)
  713. LoginSucceed(this, System.EventArgs.Empty);
  714. if (WebScraper == null)
  715. return;
  716. Action pAction = WebScraper.GetUserLoop;
  717. pAction.BeginInvoke(pAction.EndInvoke, null);
  718. ChangeStatus(69, 1337, League.Diamond, this._spamText);
  719. }
  720. private async Task<string> Message(Jid SummonerJID, params string[] pParams)
  721. {
  722. Task<string> lRes = Spamtext.ToTask<string>();
  723. var lText = await lRes;
  724. lRes.Dispose();
  725. return lText;
  726. }
  727.  
  728. private void Chat_OnMessage(object sender, Matrix.Xmpp.Client.MessageEventArgs e)
  729. {
  730.  
  731. if (!this.Logged_In)
  732. return;
  733. if (e.Message.Type == MessageType.chat)
  734. {
  735. Token.Parse(e.Message.Body.ToLower().Trim(), e.Message.From, newAction.Where(item => e.Message.Body.ToLower().Trim().IndexOf(item.Key) == 0 && !(e.Message.Body.Length == item.Key.Length) && e.Message.Body[item.Key.Length] == ' ').FirstOrDefault());
  736. }
  737. }
  738. private bool _flag = false;
  739. public void Deletefriends()
  740. {
  741. if (_flag)
  742. return;
  743. _flag = true;
  744. this._chat.RequestRoster();
  745. }
  746. private void Roster_Requested(object sender, Matrix.Xmpp.Roster.RosterEventArgs e)
  747. {
  748. if (_flag && this.Chat != null && this._logged_In && !this.disposed)
  749. this.RemoveFriend(e.RosterItem.Jid, true);
  750. }
  751. private void Roster_End(object sender, Matrix.EventArgs e)
  752. {
  753. _flag = false;
  754. }
  755. void Token_Parsed(object sender, ParsedEventArgs e)
  756. {
  757. // Result = Answer
  758. // e.Params = Params (for example: !Command Param1 Param2 ...)
  759. string Result = String.Empty;
  760. ParamAction pHolder = null;
  761. //Check whether the Command is registered or the Defaultcommand is enabled
  762. if (newAction.ContainsKey(e.ActCommand))
  763. {
  764. pHolder = newAction[e.ActCommand];
  765. }
  766. else if (DefaultCommand != null)
  767. {
  768. pHolder = DefaultCommand;
  769. }
  770. else
  771. {
  772. return;
  773. }
  774. //Call Function Asynchronous
  775. pHolder.BeginInvoke(e.User, e.Params, async item =>
  776. {
  777. var lRes = pHolder.EndInvoke(item);
  778. Result = await lRes;
  779. SendMessage(e.User, Result);
  780. lRes.Dispose();
  781. }, null);
  782.  
  783. }
  784.  
  785. public void SendMessage(Jid pUser, string pMessage)
  786. {
  787. if (Chat == null)
  788. return;
  789. Matrix.Xmpp.Client.Message newMessage = new Matrix.Xmpp.Client.Message();
  790. newMessage.To = pUser;
  791. newMessage.Type = Matrix.Xmpp.MessageType.chat;
  792. newMessage.Body = pMessage;
  793. Chat.Send(newMessage);
  794. }
  795. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement