wop commited on
Commit
39669cf
1 Parent(s): d6bf2a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -18
app.py CHANGED
@@ -18,19 +18,16 @@ event = Event()
18
  DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
19
  HF_TOKEN = os.getenv("HF_TOKEN")
20
 
21
-
22
  async def wait(job):
23
  while not job.done():
24
  await asyncio.sleep(0.2)
25
 
26
-
27
  def get_client(session: Optional[str] = None) -> grc.Client:
28
  client = grc.Client("https://wop-xxx-opengpt.hf.space/", hf_token=HF_TOKEN)
29
  if session:
30
  client.session_hash = session
31
  return client
32
 
33
-
34
  def truncate_response(response: str) -> str:
35
  ending = "...\nTruncating response to 2000 characters due to discord api limits."
36
  if len(response) > 2000:
@@ -38,7 +35,6 @@ def truncate_response(response: str) -> str:
38
  else:
39
  return response
40
 
41
-
42
  intents = discord.Intents.all()
43
  bot = commands.Bot(command_prefix="$", intents=intents)
44
 
@@ -51,16 +47,8 @@ async def uptime(ctx):
51
  days, hours = divmod(hours, 24)
52
  await ctx.send(f"Uptime: {days} days, {hours} hours, {minutes} minutes, {seconds} seconds")
53
 
54
-
55
- @bot.event
56
- async def on_ready():
57
- bot.start_time = datetime.datetime.utcnow()
58
- print(f"Logged in as {bot.user} (ID: {bot.user.id})")
59
- event.set()
60
- print("------")
61
- await update_status()
62
-
63
  async def update_status():
 
64
  while True:
65
  # Fetch the number of members in all guilds the bot is connected to
66
  member_count = sum(guild.member_count for guild in bot.guilds)
@@ -68,14 +56,19 @@ async def update_status():
68
  await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f"{member_count} users"))
69
  # Wait for 60 seconds before updating again
70
  await asyncio.sleep(60)
71
-
72
- bot.loop.create_task(update_status())
73
 
74
  @bot.event
75
- async def on_member_join(mb):
76
- channelv0 = discord.utils.get(mb.guild.channels, name = "👋wellcome-goodbye")
77
- await channelv0.send(f"Welcome to server, <@{mb.id}>! ")
 
 
 
78
 
 
 
 
 
79
 
80
  # running in thread
81
  def run_bot():
 
18
  DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
19
  HF_TOKEN = os.getenv("HF_TOKEN")
20
 
 
21
  async def wait(job):
22
  while not job.done():
23
  await asyncio.sleep(0.2)
24
 
 
25
  def get_client(session: Optional[str] = None) -> grc.Client:
26
  client = grc.Client("https://wop-xxx-opengpt.hf.space/", hf_token=HF_TOKEN)
27
  if session:
28
  client.session_hash = session
29
  return client
30
 
 
31
  def truncate_response(response: str) -> str:
32
  ending = "...\nTruncating response to 2000 characters due to discord api limits."
33
  if len(response) > 2000:
 
35
  else:
36
  return response
37
 
 
38
  intents = discord.Intents.all()
39
  bot = commands.Bot(command_prefix="$", intents=intents)
40
 
 
47
  days, hours = divmod(hours, 24)
48
  await ctx.send(f"Uptime: {days} days, {hours} hours, {minutes} minutes, {seconds} seconds")
49
 
 
 
 
 
 
 
 
 
 
50
  async def update_status():
51
+ await bot.wait_until_ready() # Wait until the bot is fully ready
52
  while True:
53
  # Fetch the number of members in all guilds the bot is connected to
54
  member_count = sum(guild.member_count for guild in bot.guilds)
 
56
  await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f"{member_count} users"))
57
  # Wait for 60 seconds before updating again
58
  await asyncio.sleep(60)
 
 
59
 
60
  @bot.event
61
+ async def on_ready():
62
+ bot.start_time = datetime.datetime.utcnow()
63
+ print(f"Logged in as {bot.user} (ID: {bot.user.id})")
64
+ event.set()
65
+ print("------")
66
+ bot.loop.create_task(update_status()) # Create the task within the on_ready event
67
 
68
+ @bot.event
69
+ async def on_member_join(mb):
70
+ channelv0 = discord.utils.get(mb.guild.channels, name="👋wellcome-goodbye")
71
+ await channelv0.send(f"Welcome to the server, <@{mb.id}>!")
72
 
73
  # running in thread
74
  def run_bot():