jmesfo0 / jmes-cogs

jmes cogs for Red-DiscordBot
MIT License
4 stars 4 forks source link

[tacoshack] Hourly Income #6

Open cool-aid-man opened 1 year ago

cool-aid-man commented 1 year ago

Getting this error on the console on Shack's hourly income.

[2023-06-04 17:00:00] [ERROR] discord.ext.tasks: Unhandled exception in internal background task 'hourly_income'. -- ```py 11 | Traceback (most recent call last): 12 | File "/home/ubuntu/redenv/lib/python3.11/site-packages/discord/ext/tasks/__init__.py", line 239, in _loop 13 | await self.coro(*args, **kwargs) 14 | File "/home/ubuntu/data/starship_main/cogs/CogManager/cogs/tacoshack/tacoshack.py", line 163, in hourly_income 15 | await schedule.run_pending() 16 | File "/home/ubuntu/data/starship_main/cogs/Downloader/lib/aioschedule/__init__.py", line 544, in run_pending 17 | await default_scheduler.run_pending() 18 | File "/home/ubuntu/data/starship_main/cogs/Downloader/lib/aioschedule/__init__.py", line 111, in run_pending 19 | return await asyncio.wait(jobs, *args, **kwargs) 20 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21 | File "/usr/local/lib/python3.11/asyncio/tasks.py", line 415, in wait 22 | raise TypeError("Passing coroutines is forbidden, use tasks explicitly.") 23 | TypeError: Passing coroutines is forbidden, use tasks explicitly. ```
jmesfo0 commented 1 year ago

I think I have addressed this issue, can you run .cog update and tell me if it works?

I was reading:

As of Python 3.8 this leads to a depreciation warning and starting from Python 3.11 it is an error. The correct way to use asyncio.wait() is by passing tasks created from your coroutines. Use create_task() to create these tasks explicitly.

Sorry for my late response, I was moving to another part of the country and did not have my computer :)

cool-aid-man commented 1 year ago

Hey James! I hope everything went smoothly with the shift. And it's okay!

I updated the cog, Got this error after I reloaded the cog,

[2023-06-25 18:11:39] [ERROR] discord.ext.tasks: Unhandled exception in internal background task 'hourly_income'. -- ```py 13 | Traceback (most recent call last): 14 | File "/home/ubuntu/redenv/lib/python3.11/site-packages/discord/ext/tasks/__init__.py", line 239, in _loop 15 | await self.coro(*args, **kwargs) 16 | File "/home/ubuntu/.local/share/Red-DiscordBot/data/dusky/cogs/CogManager/cogs/tacoshack/tacoshack.py", line 163, in hourly_income 17 | await asyncio.wait(schedule.run_pending()) 18 | File "/usr/lib/python3.11/asyncio/tasks.py", line 406, in wait 19 | raise TypeError(f"expect a list of futures, not {type(fs).__name__}") 20 | TypeError: expect a list of futures, not coroutine ``` [2023-06-25 18:13:40] [ERROR] asyncio: Task exception was never retrieved -- ```py 4 | future: exception=TypeError('expect a list of futures, not coroutine')> 5 | Traceback (most recent call last): 6 | File "/home/ubuntu/redenv/lib/python3.11/site-packages/discord/ext/tasks/__init__.py", line 264, in _loop 7 | raise exc 8 | File "/home/ubuntu/redenv/lib/python3.11/site-packages/discord/ext/tasks/__init__.py", line 239, in _loop 9 | await self.coro(*args, **kwargs) 10 | File "/home/ubuntu/.local/share/Red-DiscordBot/data/dusky/cogs/CogManager/cogs/tacoshack/tacoshack.py", line 163, in hourly_income 11 | await asyncio.wait(schedule.run_pending()) 12 | File "/usr/lib/python3.11/asyncio/tasks.py", line 406, in wait 13 | raise TypeError(f"expect a list of futures, not {type(fs).__name__}") 14 | TypeError: expect a list of futures, not coroutine ```
getFran commented 4 months ago

For anyone who encounters this problem, I found a work around to this. The only downside is that you can't schedule to update the balance at an exact time, It will run after 3600 seconds (1 hour) since the last time it was executed.

You will need to comment (recommended) / remove the following lines in the tacoshack.py file:

9 | import aioschedule as schedule
158 | schedule.every().hour.at(":00").do(self.update_balance)
167 | schedule.clear()

Now, head to the following line:

161 | @tasks.loop(seconds=1)

There you have to specify in seconds how often do you want the payments to be made. (3600 = 1 hour recommended)

Once done all of above, reload the tacoshack cog and you are all set.

PD: To @jmesfo0, I know this isn't the best solution nor how you originally planned it, but it is the easiest way to get everything working without errors.