Sinisterly
ermergerd. ANOTHER CHATANGO THREAD - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Python (https://sinister.ly/Forum-Python)
+--- Thread: ermergerd. ANOTHER CHATANGO THREAD (/Thread-ermergerd-ANOTHER-CHATANGO-THREAD)



ermergerd. ANOTHER CHATANGO THREAD - Equinox - 12-15-2013

This thread is for creating personal messaging commands for your chatango bot.

Here we go;

When making the bot class if you want personal messaging commands you're going to want to have this code in your class:

Code:
def onPMMessage(self, pm, user, body): print("[PM]"+user.name.capitalize()+": "+body)

This just lets us know when people personal message the bot. It will automatically respond, but I use this feature more of cleaning up people who spam the bot.

Now onPMMessage is different from onMessage.

For example; you can't put message.body if you were going to make the messages in the prompt for the bot, that's onMessage specific. We're going to use JUST body.

Code:
print("[PM]"+user.name.capitalize()+": "+body)

Now we already added this, but I only re-added this to reference this.

You can't put used_prefix or of that sort. In the onPMMessage case you would have to use the startswith method.

Code:
if body.startswith("ily"): pm.message(user, "You love a robot?")

That's the "ily" pm command. Now if you noticed we put "user, ...". This declares who to send the message to.

So I've compiled a few basic commands to give you guys an example.

Here's an image that shows how it works if you're still confused:

[Image: 2zg5aog.jpg]

You can do as many as you want, the only restriction to my knowledge AS OF THIS THREAD is that you cannot have spaces.

Code:
def onPMMessage(self, pm, user, body): print("[PM]"+user.name.capitalize()+": "+body) if body.startswith("ily"): pm.message(user, "You love a robot?") elif body.startswith("yes"): pm.message(user, "Are you sure?") elif body.startswith("no"): pm.message(user, "I knew it.") elif body.startswith("hello"): pm.message(user, "Hello! My name is Intellect! Nice to meet you! ^^")
That should be good. Alright people, bye.
~Dub out

#UPDATE#

I tested having spaces between words, and yes you can.


RE: ermergerd. ANOTHER CHATANGO THREAD - Anizeb - 12-15-2013

Here, this is a PM function that uses PandoraBots and a delay based on average WPM to simulate a real person replying.

Untested for like, half a year. And also really shitty uncommented code, lets not talk about this era please. >>;

Requires you to import "urllib.parse", "urllib.request", "re", and "queue" if you've not done so already.


RE: ermergerd. ANOTHER CHATANGO THREAD - Equinox - 12-15-2013

(12-15-2013, 03:24 PM)Anizeb Wrote: Requires you to import "urllib.parse", "urllib.request", and "re" if you've not done so already.

Tested on Intellect.

Traceback (most recent call last):
File "C:\Users\Grayson\Desktop\Intellect\Intellect.py", line 165, in onPMMessage
que2 = queue.Queue()
NameError: global name 'queue' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Grayson\Desktop\Intellect\Intellect.py", line 584, in <module>
Intellect.easy_start(rooms, "Intellect", password)
File "C:\Users\Grayson\Desktop\Intellect\ch.py", line 3247, in easy_start
self.main()
File "C:\Users\Grayson\Desktop\Intellect\ch.py", line 3214, in main
con._feed(data)
File "C:\Users\Grayson\Desktop\Intellect\ch.py", line 578, in _feed
self._process(food.decode("latin-1").rstrip("\r\n")) #numnumz ;3
File "C:\Users\Grayson\Desktop\Intellect\ch.py", line 608, in _process
getattr(self, func)(args)
File "C:\Users\Grayson\Desktop\Intellect\ch.py", line 700, in rcmd_msg
self._callEvent("onPMMessage", user, body)
File "C:\Users\Grayson\Desktop\Intellect\ch.py", line 868, in _callEvent
getattr(self.mgr, evt)(self, *args, **kw)
File "C:\Users\Grayson\Desktop\Intellect\Intellect.py", line 173, in onPMMessage
print("\n"+e+"\n")
TypeError: Can't convert 'NameError' object to str implicitly


RE: ermergerd. ANOTHER CHATANGO THREAD - Anizeb - 12-15-2013

Must have missed something, gimme a minute.

Edit; queue is a module, add "import queue", should work.\
Edit; Updated post to correct my mistakes.