Advertisement
Guest User

Untitled

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