lunarflu HF staff commited on
Commit
f8e106c
1 Parent(s): f02e0b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -3
app.py CHANGED
@@ -14,6 +14,7 @@ import re
14
  import gradio_client
15
  import gradio as gr
16
  from gradio_client import Client
 
17
 
18
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
19
  intents = discord.Intents.all()
@@ -32,6 +33,9 @@ worksheet = gspread_bot.open("levelbot").sheet1
32
  """"""
33
  bot_ids = [1136614989411655780, 1166392942387265536, 1158038249835610123, 1130774761031610388, 1155489509518098565, 1155169841276260546, 1152238037355474964, 1154395078735953930]
34
  """"""
 
 
 
35
 
36
  @bot.event
37
  async def on_ready():
@@ -47,9 +51,43 @@ def calculate_xp(level):
47
  return (int(level ** 3))
48
 
49
 
50
- async def add_exp(member):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  try:
52
  guild = bot.get_guild(879548962464493619)
 
53
  lvl1 = guild.get_role(1171861537699397733)
54
  lvl2 = guild.get_role(1171861595115245699)
55
  lvl3 = guild.get_role(1171861626715115591)
@@ -116,7 +154,7 @@ async def add_exp(member):
116
  async def on_message(message):
117
  try:
118
  if message.author.id not in bot_ids:
119
- await add_exp(message.author)
120
  await bot.process_commands(message)
121
  except Exception as e:
122
  print(f"on_message Error: {e}")
@@ -126,7 +164,7 @@ async def on_message(message):
126
  async def on_reaction_add(reaction, user):
127
  try:
128
  if user.id not in bot_ids:
129
- await add_exp(user)
130
  except Exception as e:
131
  print(f"on_reaction_add Error: {e}")
132
 
 
14
  import gradio_client
15
  import gradio as gr
16
  from gradio_client import Client
17
+ from huggingface_hub import HfApi, list_models, list_liked_repos, list_metrics
18
 
19
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
20
  intents = discord.Intents.all()
 
33
  """"""
34
  bot_ids = [1136614989411655780, 1166392942387265536, 1158038249835610123, 1130774761031610388, 1155489509518098565, 1155169841276260546, 1152238037355474964, 1154395078735953930]
35
  """"""
36
+ api = HfApi()
37
+ """"""
38
+
39
 
40
  @bot.event
41
  async def on_ready():
 
51
  return (int(level ** 3))
52
 
53
 
54
+ # use a command
55
+ # check xp record presence (done in add_exp)
56
+ # check discord_user_id is verified
57
+ # do add_exp for hub?
58
+ @bot.command(name='add_exp_hub')
59
+ async def add_exp_hub(ctx, discord_user_id):
60
+ try:
61
+ cell = worksheet.find(str(discord_user_id))
62
+ if cell.col = 5
63
+ # find hub_user_name
64
+ hf_user_name = worksheet.cell(cell.row, cell.col-2).value
65
+ if hf_user_name:
66
+ # check likes
67
+ likes = list_liked_repos(f"{hf_user_name}")
68
+ hf_likes_new = likes.total
69
+ hf_likes_old = worksheet.cell(cell.row, cell.col+2).value
70
+ if hf_likes_old:
71
+ hf_likes_old = int(hf_likes_old)
72
+ difference = hf_likes_new - hf_likes_old
73
+ if difference > 0:
74
+ worksheet.update(f'G{cell.row}', f'{hf_likes_new}')
75
+ """
76
+ for i in range(difference):
77
+ await add_exp(discord_user_id)
78
+ """
79
+
80
+ else:
81
+ worksheet.update(f'G{cell.row}', f'{hf_likes_new}')
82
+
83
+ except Exception as e:
84
+ print(f"add_exp_hub Error: {e}")
85
+
86
+
87
+ async def add_exp(member_id):
88
  try:
89
  guild = bot.get_guild(879548962464493619)
90
+ member = guild.get_member(member_id)
91
  lvl1 = guild.get_role(1171861537699397733)
92
  lvl2 = guild.get_role(1171861595115245699)
93
  lvl3 = guild.get_role(1171861626715115591)
 
154
  async def on_message(message):
155
  try:
156
  if message.author.id not in bot_ids:
157
+ await add_exp(message.author.id)
158
  await bot.process_commands(message)
159
  except Exception as e:
160
  print(f"on_message Error: {e}")
 
164
  async def on_reaction_add(reaction, user):
165
  try:
166
  if user.id not in bot_ids:
167
+ await add_exp(user.id)
168
  except Exception as e:
169
  print(f"on_reaction_add Error: {e}")
170