x84-extras / nodechat

IRC style multi node chatter for x/84
MIT License
2 stars 0 forks source link

AttributeError: 'int' object has no attribute 'code' #1

Closed ExileInParadise closed 5 years ago

ExileInParadise commented 6 years ago

I could really use an experienced Python guru's advice on how to modify nodechat.py to work with x/84 2.0.15 - currently it tries to work then runs into an exception I can't interpret.

BEHAVIOR Entering the 'nodechat' module from the main menu, the node chat displays. Entering regular text works. Hitting ENTER, or hitting special keys, or entering / commands generates the following exception:

ERROR MESSAGE Sun-05-13 10:25AM INFO session.py:674 sysop[ssh] runscript 'nodechat' Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] File "/home/bbs/lib/python2.7/site-packages/x84/bbs/session.py", line 363, in run Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] self.runscript(self._script_stack.pop()) Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] File "/home/bbs/lib/python2.7/site-packages/x84/bbs/session.py", line 705, in runscript Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] value = module.main(*script.args, script.kwargs) Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] File "/home/bbs/default/main.py", line 224, in main Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] gosub(item.script, *item.args, *item.kwargs) Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] File "/home/bbs/lib/python2.7/site-packages/x84/bbs/session.py", line 70, in gosub Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] return getsession().runscript(script) Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] File "/home/bbs/lib/python2.7/site-packages/x84/bbs/session.py", line 705, in runscript Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] value = module.main(script.args, script.kwargs) Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] File "/home/bbs/default/nodechat.py", line 369, in main Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] otxt = readline.process_keystroke(inp) Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] File "/home/bbs/lib/python2.7/site-packages/x84/bbs/editor.py", line 399, in process_keystroke Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] keystroke.code in self.keyset['refresh']): Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] Sun-05-13 10:25AM ERROR session.py:389 sysop[ssh] AttributeError: 'int' object has no attribute 'code' Sun-05-13 10:25AM ERROR session.py:342 sysop[ssh] resume main after general exception in nodechat

NOTES It appears blessed (and terminal which wrap it) have a code object, so it seems that the keystroke.code is referring to an underlying int, rather than the keystroke itself? Python noob so I am not sure I am interpreting this stack dump correctly.

ENVIRONMENT: Python 2.7 VirtualEnv $ python --version Python 2.7.14 $ pip list Package Version


asn1crypto 0.24.0
bcrypt 1.1.0
blessed 1.9.5
cffi 1.7.0
CherryPy 3.6.0
cryptography 2.2.2
ecdsa 0.11
enum34 1.0.4
feedparser 5.1.3
html2text 2014.12.29 idna 2.6
ipaddress 1.0.22
irc 11.0.1
jaraco.timing 1.1
jaraco.util 10.6
more-itertools 2.2
paramiko 1.18.3
pip 10.0.1
pyasn1 0.1.7
pycparser 2.10
pycrypto 2.6.1
pyOpenSSL 17.5.0
python-dateutil 2.3
requests 2.5.1
sauce 1.1
setuptools 39.1.0
six 1.9.0
sqlitedict 1.1.0
wcwidth 0.1.7
web.py 0.37
wheel 0.31.0
x84 2.0.15
xmodem 0.3.2

haliphax commented 6 years ago

This is due to the use of getch() most likely, which has been deprecated in favor of Terminal.inkey(). I'll see if I can find some time to get this cleaned up.

ExileInParadise commented 6 years ago

Ah okay, I'd seen some other notes about getch around but did not put 2+2 together there. Nodechat has 3 occurrences of getch - the import, and two calls to assign the key to input. While I am trying to learn my way through all of this I will take a stab at figuring out the correct import and replacement calls. Appreciate the steer and will see what I can come up with. If it works on my board, I will fork/branch/commit/push/merge request it for you, but I expect with your background you will beat me to it and do a better job.

ExileInParadise commented 6 years ago

Okay, around line 213, I removed the getch from import. I don't think I need to add an import for inkey since it seems to come in with the getterminal and other imports already.

line 233 I changed inp = getch() to inp = getterminal().inkey()

line 338, I changed inp = getch(POLL_KEY) to inp = getterminal.inkey(POLL_KEY)

Rereunning nodechat I got the following exception: Mon-05-21 03:15PM ERROR session.py:389 sysop[ssh] File "/home/bbs/x84/local/lib/python2.7/site-packages/x84/bbs/editor.py", line 414, in process_keystroke Mon-05-21 03:15PM ERROR session.py:389 sysop[ssh] if ord(keystroke) >= 0x20: Mon-05-21 03:15PM ERROR session.py:389 sysop[ssh] Mon-05-21 03:15PM ERROR session.py:389 sysop[ssh] TypeError: ord() expected a character, but string of length 0 found

So, I added this small block under the inp = getterminal().inkey(POLLKEY) as new lines 339-340: if inp == u'': inp = None

That seemed to let me into the nodechat without exception. But... I noticed the following behavior with nodechat like this: Once you reach the last line of the screen, more input does not trigger a "scroll" - the screen just stays filled until you exit with /quit. I feel like I am on the right track, maybe, but... not 100% there? Missing something somewhere...

ExileInParadise commented 6 years ago

Spoke too soon - when I tried /help in a nodechat, I got the following as well: Mon-05-21 03:33PM ERROR session.py:389 sysop[ssh] File "/home/bbs/x84/bbs/default/nodechat.py", line 197, in get_pager Mon-05-21 03:33PM ERROR session.py:389 sysop[ssh] content[row] = ucs Mon-05-21 03:33PM ERROR session.py:389 sysop[ssh] Mon-05-21 03:33PM ERROR session.py:389 sysop[ssh] TypeError: 'unicode' object does not support item assignment Mon-05-21 03:33PM ERROR session.py:342 sysop[ssh] resume main after general exception in nodechat

Note sure if any of this helps or not, but its is educational.

ExileInParadise commented 6 years ago

Was able to clean up everything pylint was sad about except for one warning about the NICKS and CHANNEL variables.

$ pylint nodechat.py No config file found, using default configuration ***** Module x84.zeroone.nodechat W: 44, 4: Using the global statement (global-statement)


Your code has been rated at 9.95/10 (previous run: 9.95/10, +0.00)

The changed code I'm messing with is here if you want to take a look at what I've got so far. https://pastebin.com/Rnj568yH

I am still stuck at the "TypeError: 'unicode' object does not support item assignment in content[row] = ucs which I posted above.

haliphax commented 6 years ago

I think you'll have to build a new content object manually with string concatenation and then assign it to new_pager, as you can't index into unicode objects (as illustrated by the error message).

ExileInParadise commented 6 years ago

Thanks haliphax - I've been trying various attempts to do that but not really making useful progress. But I have a long weekend coming up so I can hopefully sit down and sort it out. I am getting caught up in some of the unicode sequence juggling, and it looks like the "quick hack" to scan needs to be completely replaced since its going one index item at a time but looking for sequences in slices of the content to replace. I keep coming "close" by trial and error rather than having a really good understanding of exactly what is happening, the inputs, the process, and the outputs so that I understand the best thing to change.

haliphax commented 6 years ago

I have managed to get it to work without bombing out, but it seems as though the Pager object no longer scrolls text automatically when it reaches the edge of the visible area. I'm hacking a workaround for that, but it should ultimately be fixed in the base Pager class that's part of the x84 API. Since @jquast isn't particularly interested in maintaining x84 any longer, and I'm not altogether familiar with all of its bits and pieces, I wouldn't hold my breath (re: the Pager fix) if I were you. šŸ˜¦ Nevertheless, I should be able to get nodechat to work with some tape and paper clips.

haliphax commented 6 years ago

Bah... and I've somehow introduced a bug where it is constantly refreshing the screen and slows down further with each new message that is sent. The use of global events also has no check to ensure that they are chat events, which was leading to some issues with other scripts on my board (since I use global for other nifty things). It's looking like maybe a full rewrite would be better. šŸ˜’

haliphax commented 6 years ago

I have managed to mostly rewrite nodechat.py by cannibalizing the ircchat.py script from the default board. I only have a couple of bits to clean up and then it will be ready. It no longer has channels, however - just one global channel that everyone is thrown into. It also no longer lists who is in chat. If those features are important to anyone, I can dig deeper and just try to rebuild the existing nodechat.py by replacing the use of a Pager object with a dequeue and from-the-bottom-up output the way that ircchat.py operates.

ExileInParadise commented 6 years ago

Wow it sounds like you've gone much further in a short time than I could. It sounds like your idea of rebuilding the nodechat with dequeue sounds like a great longerm improvement. Your comments also give me some places to look as well. Sad to hear Jeff is no longer really interested - this is a really cool platform and the potential of taking it further is so large - just at the time when BBSes are regaining some steam with folks (like me) who have been disenchanted with what's happened/happening to the Internet.

haliphax commented 6 years ago

I can throw up what I currently have as a gist if you need a quick fix, and see about overhauling the existing version to use dequeue instead of Pager.

For what it's worth, we're still fairly active in #1984 on EFNet... there's just not a lot of active development going on since the principal author of the engine is no longer participating. A lot of the really low-level terminal stuff is pretty far over my head; I just love x/84 for its flexibility and API, and so I've contributed wherever I've been able to.

I have plans to gut the messaging system and use plain SQLite instead of SqliteDict so that we can get actual relational data and possibly open it up for FidoNet (FTN) or QWK messaging at some point, but life gets in the way (especially now, as I have a 2 y/o daughter).

jquast commented 6 years ago

Yeah sorry folks, Iā€™d love to play but my day job is demandig!

haliphax commented 6 years ago

It's all good, man - such is the curse of open source. But, it being open source, enterprising individuals with the drive and the free time are welcome to keep the ball moving.

We'll have to do a somewhat significant rebuilding at some point, anyway, since Python 2.7.x is going to be EOL in 2020.

haliphax commented 6 years ago

@ExileInParadise - Here's what I've got: https://gist.github.com/haliphax/1aec62815fa76684d3351897ed8580d2

ExileInParadise commented 6 years ago

@jquast it's all good man - I only recently found this code and it's fantastic - what inspired me to get back into BBSing after I took down my MajorBBS in 1997 rather than just thinking about it. I totally get the demanding job - mine goes in cycles which makes keeping up with complex projects tough. I did fork x84 and hope to start contributing back user, sysop, and developer docs and other pieces for it as I grok each file in fullness.

@haliphax Awesomesauce man, I am mere hours away from the start of a 4 day weekend where I have nothing preplanned except working on my board. I do plan to hook up to #1984 this weekend, and the shared messages going in the nearish future. I appreciate your hacking on the nodechat and the gist and will get in and get grinding with it shortly.

slyderc commented 5 years ago

Just found this thread after wondering publicly about x84's future status over in the main project. Finding the project has rekindled my Python learning and inspired me to rewrite an old BBS I used to run back in the day. Would love to hear from @ExileInParadise @haliphax or anyone else on efforts since @jquast has moved on... -ward and upward I hope. šŸ˜„

ExileInParadise commented 5 years ago

Jump into the IRC channel - we're all there. As far as the future goes - if you're running or coding on X84 - it has a future.

ExileInParadise commented 5 years ago

Going to close this issue since @haliphax threw down a working quick and dirty node chat a while back and I didn't realize I had the powerz to close this myself? Giving it a shot. Someday I must learn python, git, and github...