bot.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import pubg_lablab
  2. from uuid import uuid4
  3. from telegram.ext import MessageHandler, Filters, Updater, InlineQueryHandler
  4. from telegram import InlineQueryResultArticle, InputTextMessageContent, ParseMode
  5. bg = pubg_lablab.Battlegrounds('Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI1NzdjYzFlMC1jM2UwLTAxMzYtOWJiZS02YjYxOGIyZjU5NzQiLCJpc3MiOiJnYW1lbG9ja2VyIiwiaWF0IjoxNTQxNTAxNzA1LCJwdWIiOiJibHVlaG9sZSIsInRpdGxlIjoicHViZyIsImFwcCI6InB1YmdfdGVsZWdyYW0ifQ.yANNOqbPTDA0aBxMvriJ35c6Fg2b2g7JC9esndsXKOg', 'pc_eu')
  6. def bot_query(bot, update):
  7. query = update.inline_query.query
  8. print(query)
  9. allowed_users = ['Vogelstrauss', 'tsi_tsi', 'Ceelbee', 'DerDeckel', 'th3fr3ddy', 'Konfusio']
  10. # allowed_users = ['tsi_tsi']
  11. if query in allowed_users:
  12. squad_lifetime_stats = bg.lifetime(bg.player(query).id).squad
  13. out = query + " (Rounds: " + str(squad_lifetime_stats.roundsPlayed) + ")" \
  14. + "\nKills: " + str(squad_lifetime_stats.kills) \
  15. + "\nHeadshot Kills: " + str(squad_lifetime_stats.headshotKills) \
  16. + "\nAssists: " + str(squad_lifetime_stats.assists) \
  17. + "\nRoad Kills: " + str(squad_lifetime_stats.roadKills) \
  18. + "\nLongest Shot: " + str(squad_lifetime_stats.longestKill)
  19. options = [
  20. InlineQueryResultArticle(
  21. id=uuid4(),
  22. title="Total Kills",
  23. input_message_content=InputTextMessageContent(out , parse_mode = "HTML"))
  24. ]
  25. print(options)
  26. if query == 'rank':
  27. toplist = {}
  28. for i in allowed_users:
  29. stats = bg.lifetime(bg.player(i).id).squad
  30. toplist[i] = stats.kills
  31. toplist = sorted(toplist.items(), key=lambda kv: kv[1], reverse=True)
  32. out = "Ranking\n"
  33. n = 1
  34. for i in toplist:
  35. out += str(n) + ". " + str(i[0]) + " - " + str(i[1]) + '\n'
  36. n = n + 1
  37. options = [
  38. InlineQueryResultArticle(
  39. id=uuid4(),
  40. title="Ranking",
  41. input_message_content=InputTextMessageContent(out , parse_mode = "HTML"))
  42. ]
  43. if query == 'rank kd':
  44. toplist = {}
  45. for i in allowed_users:
  46. stats = bg.lifetime(bg.player(i).id).squad
  47. toplist[i] = round(stats.kills/stats.losses,2)
  48. toplist = sorted(toplist.items(), key=lambda kv: kv[1], reverse=True)
  49. out = "Ranking (KD Ratio)\n"
  50. n = 1
  51. for i in toplist:
  52. out += str(n) + ". " + str(i[0]) + " - " + str(i[1]) + '\n'
  53. n = n + 1
  54. options = [
  55. InlineQueryResultArticle(
  56. id=uuid4(),
  57. title="Ranking",
  58. input_message_content=InputTextMessageContent(out , parse_mode = "HTML"))
  59. ]
  60. update.inline_query.answer(options, cache_time=0)
  61. updater = Updater(token='627697353:AAEuYCZSPfMg9ll0D0Gf3QhA9G21wJh97Wk')
  62. dispatcher = updater.dispatcher
  63. dispatcher.add_handler(InlineQueryHandler(bot_query))
  64. updater.start_polling(clean=False)
  65. print ("Running")
  66. updater.idle()