Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run example casket.py hang #426

Closed
3 tasks done
feeops opened this issue Dec 22, 2023 · 3 comments
Closed
3 tasks done

run example casket.py hang #426

feeops opened this issue Dec 22, 2023 · 3 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@feeops
Copy link

feeops commented Dec 22, 2023

Summary

run example casket.py hang

Reproduction Steps

example code

from __future__ import annotations

import steam
import json
from steam.ext import commands, csgo

f = open("example.maFile", "r")
content = f.read()
f.close()

print(content)

identity_secret = json.loads(content).get("identity_secret")
shared_secret = json.loads(content).get("shared_secret")
print(identity_secret)
print(shared_secret)


class BackpackItemConverter(commands.Converter[csgo.BackpackItem[
    csgo.ClientUser]]):  # custom converter to get `BackpackItem`s from the bot's inventory
    async def convert(self, ctx: commands.Context[MyBot], argument: str) -> csgo.BackpackItem[csgo.ClientUser]:
        backpack = await ctx.bot.user.inventory(steam.CSGO)
        try:
            asset_id = int(argument)
        except ValueError:
            item = steam.utils.get(backpack, name=argument)
        else:
            item = steam.utils.get(backpack, id=asset_id)

        if item is None:
            raise commands.BadArgument(f"{argument!r} is not present in the backpack")
        return item


class MyBot(csgo.Bot):
    @commands.group
    async def casket(self, ctx: commands.Context, *, casket: csgo.BackpackItem):
        """Get info about a casket/storage container."""
        if not isinstance(casket, csgo.Casket):
            return await ctx.send(f"{casket.name!r} is not a casket.")

        contents = await casket.contents()
        await ctx.send(
            f"""Info on {casket.custom_name!r}:
            - contains {casket.contained_item_count} items
            - first item in it is {contents[0].id}
            """
        )

    @casket.command
    async def add(self, ctx: commands.Context, item: csgo.BackpackItem, casket: csgo.BackpackItem):
        """Add an item to a casket."""
        if not isinstance(casket, csgo.Casket):
            return await ctx.send(f"{casket.name} is not a casket.")

        await casket.add(item)
        await ctx.send("👌")

    @casket.command
    async def remove(self, ctx: commands.Context, item_id: int, casket: csgo.BackpackItem):
        """Remove an item from a casket."""
        if not isinstance(casket, csgo.Casket):
            return await ctx.send(f"{casket.name} is not a casket.")

        contents = await casket.contents()
        casket_item = steam.utils.get(contents, asset_id=item_id)
        if casket_item is None:
            return await ctx.send(f"{item_id} is not in the casket.")
        await casket.remove(casket_item)
        await ctx.send("👌")


bot = MyBot(command_prefix="!")
bot.run(username="xxxx", password="xxxx", identity_secret=identity_secret, shared_secret=shared_secret)

Expected Results

output something

Actual Results

no output

System Information

OS: debian 12
python version: 3.12
steam.py: lastest main version(commit id:4c3644d0f63d832453d4b2d710fbc049c020e41b)

Checklist

  • I have searched the issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my username, password, shared/identity secrets and refresh/access tokens from display, if visible.
@feeops feeops added the bug Something isn't working label Dec 22, 2023
@Gobot1234
Copy link
Owner

I can't see anything wrong here so I'm either going to need logs or you'll need to do more debugging to figure out where it's hanging

@Gobot1234 Gobot1234 added the no-repro I couldn't reproduce this issue with the information presented in the issue label Dec 22, 2023
@feeops
Copy link
Author

feeops commented Dec 22, 2023

I can't see anything wrong here so I'm either going to need logs or you'll need to do more debugging to figure out where it's hanging

I add debug=True,this is the log

future: <Task finished name='steam.py GC 730: parse_gc_client_connect' coro=<GCState.parse_gc_client_connect() done, defined at /usr/local/lib/python3.12/site-packages/steam/ext/csgo/state.py:100> exception=AttributeError("'CasketItem' object has no attribute 'inventory'") created at /usr/local/lib/python3.12/asyncio/tasks.py:420>
source_traceback: Object created at (most recent call last):
  File "/opt/casket_move/main.py", line 73, in <module>
    bot.run(username="xxx", password="xxx",
  File "/usr/local/lib/python3.12/site-packages/steam/client.py", line 414, in run
    asyncio.run(runner(), debug=debug)
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 671, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 638, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1963, in _run_once
    handle._run()
  File "/usr/local/lib/python3.12/asyncio/events.py", line 84, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.12/site-packages/steam/client.py", line 470, in poll
    await state.ws.poll_event()
  File "/usr/local/lib/python3.12/site-packages/steam/gateway.py", line 699, in poll_event
    return self.receive(message.data)  # type: ignore
  File "/usr/local/lib/python3.12/site-packages/steam/gateway.py", line 744, in receive
    result = event_parser(self._state, msg)
  File "/usr/local/lib/python3.12/site-packages/steam/state.py", line 2995, in handle_multi
    self.ws.receive(data[4 : 4 + size])
  File "/usr/local/lib/python3.12/site-packages/steam/gateway.py", line 744, in receive
    result = event_parser(self._state, msg)
  File "/usr/local/lib/python3.12/site-packages/steam/_gc/state.py", line 141, in parse_gc_message
    task = asyncio.create_task(result, name=f"steam.py GC {app_id}: {event_parser.__name__}")
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 420, in create_task
    task = loop.create_task(coro)
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/steam/ext/csgo/state.py", line 105, in parse_gc_client_connect
    await self.update_backpack(*(base.Item().parse(item_data) for item_data in cache.object_data))
  File "/usr/local/lib/python3.12/site-packages/steam/ext/csgo/state.py", line 146, in update_backpack
    self.set("position", 0 if is_new else gc_item.inventory & 0xFFFF)
                                          ^^^^^^^^^^^^^^^^^
AttributeError: 'CasketItem' object has no attribute 'inventory'
Executing <Task pending name='steam.py GC 730: parse_gc_client_connect' coro=<GCState.parse_gc_client_connect() running at /usr/local/lib/python3.12/site-packages/steam/ext/csgo/state.py:105> wait_for=<Future pending cb=[Task.task_wakeup()] created at /usr/local/lib/python3.12/asyncio/base_events.py:447> cb=[set.remove()] created at /usr/local/lib/python3.12/asyncio/tasks.py:420> took 2.782 seconds
Executing <Task pending name='Task-22' coro=<Client._login.<locals>.poll() running at /usr/local/lib/python3.12/site-packages/steam/client.py:470> wait_for=<Future pending cb=[Task.task_wakeup()] created at /usr/local/lib/python3.12/asyncio/base_events.py:447> cb=[Client._login.<locals>.maybe_set_result() at /usr/local/lib/python3.12/site-packages/steam/client.py:507] created at /usr/local/lib/python3.12/asyncio/tasks.py:420> took 4.662 seconds
Executing <Task finished name='steam.py GC 730: parse_gc_client_connect' coro=<GCState.parse_gc_client_connect() done, defined at /usr/local/lib/python3.12/site-packages/steam/ext/csgo/state.py:100> exception=AttributeError("'CasketItem' object has no attribute 'inventory'") created at /usr/local/lib/python3.12/asyncio/tasks.py:420> took 2.723 seconds
Task exception was never retrieved
future: <Task finished name='steam.py GC 730: parse_gc_client_connect' coro=<GCState.parse_gc_client_connect() done, defined at /usr/local/lib/python3.12/site-packages/steam/ext/csgo/state.py:100> exception=AttributeError("'CasketItem' object has no attribute 'inventory'") created at /usr/local/lib/python3.12/asyncio/tasks.py:420>
source_traceback: Object created at (most recent call last):
  File "/opt/casket_move/main.py", line 73, in <module>
    bot.run(username="xxxx", password="xxxx",
  File "/usr/local/lib/python3.12/site-packages/steam/client.py", line 414, in run
    asyncio.run(runner(), debug=debug)
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 671, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 638, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1963, in _run_once
    handle._run()
  File "/usr/local/lib/python3.12/asyncio/events.py", line 84, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.12/site-packages/steam/client.py", line 470, in poll
    await state.ws.poll_event()
  File "/usr/local/lib/python3.12/site-packages/steam/gateway.py", line 699, in poll_event
    return self.receive(message.data)  # type: ignore
  File "/usr/local/lib/python3.12/site-packages/steam/gateway.py", line 744, in receive
    result = event_parser(self._state, msg)
  File "/usr/local/lib/python3.12/site-packages/steam/state.py", line 2995, in handle_multi
    self.ws.receive(data[4 : 4 + size])
  File "/usr/local/lib/python3.12/site-packages/steam/gateway.py", line 744, in receive
    result = event_parser(self._state, msg)
  File "/usr/local/lib/python3.12/site-packages/steam/_gc/state.py", line 141, in parse_gc_message
    task = asyncio.create_task(result, name=f"steam.py GC {app_id}: {event_parser.__name__}")
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 420, in create_task
    task = loop.create_task(coro)
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/steam/ext/csgo/state.py", line 105, in parse_gc_client_connect
    await self.update_backpack(*(base.Item().parse(item_data) for item_data in cache.object_data))
  File "/usr/local/lib/python3.12/site-packages/steam/ext/csgo/state.py", line 146, in update_backpack
    self.set("position", 0 if is_new else gc_item.inventory & 0xFFFF)
                                          ^^^^^^^^^^^^^^^^^
AttributeError: 'CasketItem' object has no attribute 'inventory'
^CExecuting <Task pending name='steam.py: parse_notification' coro=<ConnectionState.parse_notification() running at /usr/local/lib/python3.12/site-packages/steam/state.py:2417> wait_for=<_GatheringFuture pending cb=[Task.task_wakeup()] created at /usr/local/lib/python3.12/asyncio/tasks.py:712> cb=[SteamWebSocket.parser_callback()] created at /usr/local/lib/python3.12/asyncio/tasks.py:420> took 1.887 seconds

And can you rewrite this lib with golang?
Like this
https://github.com/0xAozora/steam

@Gobot1234 Gobot1234 added duplicate This issue or pull request already exists and removed no-repro I couldn't reproduce this issue with the information presented in the issue labels Dec 22, 2023
@Gobot1234
Copy link
Owner

This is a duplicate of #405 which I'm still not entirely sure how to fix

@Gobot1234 Gobot1234 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants