![]() |
TwitterBot
Links approved by Moonie.
Twitter is a social-networking site which allows you to post about what you're doing, or to send short messages to all of your friends. For example, if you are walking down the street and see a monkey, you can pull out your phone, and send a text message to Twitter saying "There's a monkey walking down the street!" which will then show up on your Twitter page, and be sent to everyone watching you (and, possibly, to their mobile devices). TwitterBot is a script which does 3 things. I'll break it up and describe each thing that it does. 1. Access recent Tweets and display them. TwitterBot reads the Twitter RSS feed for each of the members specified. It figures out which Tweets are new, and then displays them by stating the message in RC chat, and also by alerting every user on the alert list, and PMing them the contents. For example, I can send a Twitter message from my phone, saying "Hey, guys. I'll be back in half an hour; did you get any work done?". 2. Sending messages Twitter does not work in a classic PM-style; instead, you post an update, and everyone sees it. So, there is no need to reply when you can just send a message. Because of the way the Twitter API is set up, you have to use a PHP file to send a message; I take care of all this for you, however. I will explain this later. To send a message, you can say "/npc twitter sendmessage Hello, we got a lot done! I can't wait to show you when you get back!". This would then be sent to my phone, where I can reply. 3. Commands TwitterBot comes with two pretty suckish commands, but it would be easy to add more on to. The commands work where you request information, and the bot returns it. So, if I send a Twitter update that says ".playercount", it would tell me the current playercount on my server. If I send one that says ".players", it would tell me all the accounts on my server. So, I can see that the graphics admin is currently on; I can then send a message asking them if they finished a graphic yet. Script Copy and paste this code in to a wNPC named "TwitterBot", and customize the options at the top. I will explain these below. PHP Code:
this.username - This is the username of your Twitter account which you will be sending messages through. I highly recommend creating a new account. this.password - The password of the username; yes, it must be stored in clear text. This is why I recommend you create a new account. this.server - The name of the server you are currently on. this.url - The URL of the PHP file (see below). this.users - The list of Twitter accounts that you want to monitor Tweets from. this.alert - These are the accounts that should receive and alert and be PMed Tweets when they arrive. this.checkspeed - This is the speed at which TwitterBot checks for new messages; I recommend 5 or 10. This is all you will need to change in this script. Now, open the Control-NPC script, and add at the bottom (or to the existing onRCChat function) this code: PHP Code:
I have a PHP file hosted on my server which will work fine with this script; however, I warn you that it may go down, and may be slow. It is hosted in a computer at my house, and therefor any power outages will put it down. I cannot guarantee that it will always be there, either. If you are worried about security, I strongly recommend that you use the script I am providing and host it on your own server. This will also probably result in better up-time and speed. Paste this in a file called twitter.php -- be sure to change this.url in the script to reflect this. PHP Code:
This is all you will need to know to run TwitterBot! Be sure to leave comments and criticism, and ask for help if you need it! Suggestions are also welcome so that I can make an improved version! |
Nifty.
|
Quote:
|
That's pretty cool :p nice job
|
Extremely useful!
Very nice work! |
Quote:
More like a nifty and a very nice script ^^ And that last line sounded a little bit sarcastic? Anyways, again Chris, nifty script :p |
Quote:
Thanks Bloo ;o |
Quote:
|
Quote:
I'd never get a link approved ;) |
Non-sarcasm
lol I'll upload the PHP script to my server-- I'll post the link later. |
I'm wondering if you really need php? It's possible to make post-requests and similar with TSocket if it's enabled on the server.
|
Quote:
Perhaps it wouldn't be out of line to request a function similar to requesturl for post data? Maybe something like, requestpost(url, "a=1&b=2") which would handle performing the POST request for us and wouldn't require us to request sockets be enabled. Would probably also be nice to get a url encoding function (percent/form encoding) so data is properly encoded when performing the request. |
I think using TSocket is simplier, since the command would need to handle authentication, severel parameters etc.
This is a GET request with authentication: PHP Code:
Update: added urlencode(url) on Kingdoms, can upload a version for hosted servers end of the week along with the recent /scripthelp improvements. |
Quote:
|
Quote:
The problem is that for it to be released on the Code Gallery, I wanted it to be as simple as possible, and code that would only work if you enabled sockets on their server didn't seem like a good solution. |
| All times are GMT +2. The time now is 01:04 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.