Advertisement
Guest User

Untitled

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