mirror of
https://github.com/RussellChamp/tilde-projects.git
synced 2026-10-28 00:22:34 +00:00
First tilde projects commit
This commit is contained in:
1 parent
9bcadfc4a7
commit
726861fae6
40 files changed
+20890
No files matched your search
@@ -0,0 +1,16 @@
|
||||
import time
|
||||
import re
|
||||
|
||||
def format_message(message):
|
||||
pattern = r'^:.*\!~(.*)@.* (.*) (.*) :(.*)'
|
||||
now = int(time.time())
|
||||
matches = re.match(pattern, message)
|
||||
if not matches:
|
||||
return ''
|
||||
|
||||
nick = matches.group(1).strip()
|
||||
command = matches.group(2).strip()
|
||||
channel = matches.group(3).strip()
|
||||
message = matches.group(4).strip()
|
||||
|
||||
return "%s\t%s\t%s\t%s\t%s" % (now, nick, command, channel, message)
|
||||
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
# Return a list of users on this system
|
||||
|
||||
def get_users():
|
||||
# thanks, ~dan!
|
||||
users = []
|
||||
with open("/etc/passwd", "r") as f:
|
||||
for line in f:
|
||||
if "/bin/bash" in line:
|
||||
u = line.split(":")[0] # Grab all text before first ':'
|
||||
users.append(u)
|
||||
|
||||
return users
|
||||
Binary file not shown.
+3130
File diff suppressed because it is too large.
Load diff
Binary file not shown.
@@ -0,0 +1,65 @@
|
||||
# integer number to english word conversion
|
||||
# can be used for numbers as large as 999 vigintillion
|
||||
# (vigintillion --> 10 to the power 60)
|
||||
# tested with Python24 vegaseat 07dec2006
|
||||
def int2word(n):
|
||||
"""
|
||||
convert an integer number n into a string of english words
|
||||
"""
|
||||
# break the number into groups of 3 digits using slicing
|
||||
# each group representing hundred, thousand, million, billion, ...
|
||||
n3 = []
|
||||
r1 = ""
|
||||
# create numeric string
|
||||
ns = str(n)
|
||||
for k in range(3, 33, 3):
|
||||
r = ns[-k:]
|
||||
q = len(ns) - k
|
||||
# break if end of ns has been reached
|
||||
if q < -2:
|
||||
break
|
||||
else:
|
||||
if q >= 0:
|
||||
n3.append(int(r[:3]))
|
||||
elif q >= -1:
|
||||
n3.append(int(r[:2]))
|
||||
elif q >= -2:
|
||||
n3.append(int(r[:1]))
|
||||
r1 = r
|
||||
|
||||
#print n3 # test
|
||||
|
||||
# break each group of 3 digits into
|
||||
# ones, tens/twenties, hundreds
|
||||
# and form a string
|
||||
nw = ""
|
||||
for i, x in enumerate(n3):
|
||||
b1 = x % 10
|
||||
b2 = (x % 100)//10
|
||||
b3 = (x % 1000)//100
|
||||
#print b1, b2, b3 # test
|
||||
if x == 0:
|
||||
continue # skip
|
||||
else:
|
||||
t = thousands[i]
|
||||
if b2 == 0:
|
||||
nw = ones[b1] + t + nw
|
||||
elif b2 == 1:
|
||||
nw = tens[b1] + t + nw
|
||||
elif b2 > 1:
|
||||
nw = twenties[b2] + ones[b1] + t + nw
|
||||
if b3 > 0:
|
||||
nw = ones[b3] + "hundred " + nw
|
||||
return nw
|
||||
############# globals ################
|
||||
ones = ["", "one ","two ","three ","four ", "five ",
|
||||
"six ","seven ","eight ","nine "]
|
||||
tens = ["ten ","eleven ","twelve ","thirteen ", "fourteen ",
|
||||
"fifteen ","sixteen ","seventeen ","eighteen ","nineteen "]
|
||||
twenties = ["","","twenty ","thirty ","forty ",
|
||||
"fifty ","sixty ","seventy ","eighty ","ninety "]
|
||||
thousands = ["","thousand ","million ", "billion ", "trillion ",
|
||||
"quadrillion ", "quintillion ", "sextillion ", "septillion ","octillion ",
|
||||
"nonillion ", "decillion ", "undecillion ", "duodecillion ", "tredecillion ",
|
||||
"quattuordecillion ", "sexdecillion ", "septendecillion ", "octodecillion ",
|
||||
"novemdecillion ", "vigintillion "]
|
||||
Binary file not shown.
Whitespace-only changes.
Binary file not shown.
@@ -0,0 +1,42 @@
|
||||
def pretty_date(time=False):
|
||||
"""
|
||||
Get a datetime object or a int() Epoch timestamp and return a
|
||||
pretty string like 'an hour ago', 'Yesterday', '3 months ago',
|
||||
'just now', etc
|
||||
"""
|
||||
from datetime import datetime
|
||||
now = datetime.now()
|
||||
if type(time) is int:
|
||||
diff = now - datetime.fromtimestamp(time)
|
||||
elif isinstance(time,datetime):
|
||||
diff = now - time
|
||||
elif not time:
|
||||
diff = now - now
|
||||
second_diff = diff.seconds
|
||||
day_diff = diff.days
|
||||
|
||||
if day_diff < 0:
|
||||
return ''
|
||||
|
||||
if day_diff == 0:
|
||||
if second_diff < 10:
|
||||
return "just now"
|
||||
if second_diff < 60:
|
||||
return str(second_diff) + " seconds ago"
|
||||
if second_diff < 120:
|
||||
return "a minute ago"
|
||||
if second_diff < 3600:
|
||||
return str(second_diff / 60) + " minutes ago"
|
||||
if second_diff < 7200:
|
||||
return "an hour ago"
|
||||
if second_diff < 86400:
|
||||
return str(second_diff / 3600) + " hours ago"
|
||||
if day_diff == 1:
|
||||
return "Yesterday"
|
||||
if day_diff < 7:
|
||||
return str(day_diff) + " days ago"
|
||||
if day_diff < 31:
|
||||
return str(day_diff / 7) + " weeks ago"
|
||||
if day_diff < 365:
|
||||
return str(day_diff / 30) + " months ago"
|
||||
return str(day_diff / 365) + " years ago"
|
||||
Binary file not shown.
Executable
+118
@@ -0,0 +1,118 @@
|
||||
#!/usr/bin/python
|
||||
# http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python
|
||||
|
||||
# Import some necessary libraries.
|
||||
import socket
|
||||
import os
|
||||
import sys
|
||||
from optparse import OptionParser
|
||||
|
||||
import get_users
|
||||
import mentions
|
||||
import formatter
|
||||
|
||||
parser = OptionParser()
|
||||
|
||||
parser.add_option("-s", "--server", dest="server", default='127.0.0.1',
|
||||
help="the server to connect to", metavar="SERVER")
|
||||
parser.add_option("-c", "--channel", dest="channel", default='#tildetown',
|
||||
help="the channel to join", metavar="CHANNEL")
|
||||
parser.add_option("-n", "--nick", dest="nick", default='quote_bot',
|
||||
help="the nick to use", metavar="NICK")
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
def ping():
|
||||
ircsock.send("PONG :pingis\n")
|
||||
|
||||
def sendmsg(chan , msg):
|
||||
ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n")
|
||||
|
||||
def joinchan(chan):
|
||||
ircsock.send("JOIN "+ chan +"\n")
|
||||
|
||||
def hello():
|
||||
ircsock.send("PRIVMSG "+ channel +" :Hello!\n")
|
||||
|
||||
def random_quote(channel):
|
||||
quote = os.popen("/home/frs/quotes/randquote.py").read()
|
||||
if len(quote) >= 256:
|
||||
quote = quote[:253] + '...'
|
||||
ircsock.send("PRIVMSG "+ channel +" :" + quote + "\n")
|
||||
|
||||
def haiku(channel):
|
||||
h = os.popen("haiku").read().replace("\n", " // ")
|
||||
ircsock.send("PRIVMSG "+ channel +" :" + h + "\n")
|
||||
|
||||
def connect(server, channel, botnick):
|
||||
ircsock.connect((server, 6667))
|
||||
ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :This bot is a result of a tutoral covered on http://shellium.org/wiki.\n") # user authentication
|
||||
ircsock.send("NICK "+ botnick +"\n")
|
||||
|
||||
joinchan(channel)
|
||||
|
||||
def get_user_from_message(msg):
|
||||
try:
|
||||
i1 = msg.index(':') + 1
|
||||
i2 = msg.index('!')
|
||||
return msg[i1:i2]
|
||||
except ValueError:
|
||||
return ""
|
||||
|
||||
def say_mentions(user, message):
|
||||
nick = get_user_from_message(message)
|
||||
menschns = os.popen("/home/karlen/bin/mensch -u %s -t 24 -z +0" % (user)).read().replace("\t", ": ").split("\n")
|
||||
for mention in menschns:
|
||||
if not "" == mention:
|
||||
toSend = "PRIVMSG "+ nick + " :" + mention + "\n"
|
||||
if len(toSend) >= 256:
|
||||
toSend = toSend[:253] + '...'
|
||||
ircsock.send(toSend)
|
||||
|
||||
def say_chatty(channel):
|
||||
chattyOut = os.popen("/home/karlen/bin/chatty").read().split("\n")
|
||||
for line in chattyOut:
|
||||
if line:
|
||||
ircsock.send("PRIVMSG "+ channel + " :" + line + "\n")
|
||||
|
||||
def listen():
|
||||
while 1:
|
||||
|
||||
ircmsg = ircsock.recv(2048)
|
||||
ircmsg = ircmsg.strip('\n\r')
|
||||
|
||||
if ircmsg.find("PING :") != -1:
|
||||
ping()
|
||||
|
||||
formatted = formatter.format_message(ircmsg)
|
||||
|
||||
if "" == formatted:
|
||||
continue
|
||||
|
||||
print formatted
|
||||
|
||||
split = formatted.split("\t")
|
||||
time = split[0]
|
||||
user = split[1]
|
||||
messageText = split[2]
|
||||
|
||||
if ircmsg.find(":!quote") != -1:
|
||||
random_quote(options.channel)
|
||||
|
||||
if ircmsg.find(":!mentions") != -1:
|
||||
say_mentions(user, ircmsg)
|
||||
|
||||
if ircmsg.find(":!chatty") != -1:
|
||||
say_chatty(options.channel)
|
||||
|
||||
if ircmsg.find(":!haiku") != -1:
|
||||
haiku(options.channel)
|
||||
|
||||
if ircmsg.find("PING :") != -1:
|
||||
ping()
|
||||
|
||||
sys.stdout.flush()
|
||||
|
||||
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
connect(options.server, options.channel, options.nick)
|
||||
listen()
|
||||
@@ -0,0 +1,217 @@
|
||||
What was the last picture you took with your phone?
|
||||
Do you know any big gossipers?
|
||||
Have you been pulled over by a cop?
|
||||
Do you know your heritage?
|
||||
What have you always wanted? Did you ever get it?
|
||||
What kind of sickness have you lied about so you wouldn't go to work?
|
||||
What was the last lie you told?
|
||||
Have you ever danced in the rain?
|
||||
What is your blood type?
|
||||
Have you ever been in a car accident?
|
||||
What was the weirdest prank call that you have made?
|
||||
Best compliment you have received?
|
||||
Do you trust anyone with your life?
|
||||
What is your greatest strength or weakness?
|
||||
What is your perfect pizza?
|
||||
What was your first thought when you woke up this morning
|
||||
Do you get along with your family? Why or why not?
|
||||
Ugly and live forever, or attractive and die in a year?
|
||||
You discover that your wonderful one year old child is because of a mix up at the hospital and not yours. Would you want to exchange the child to correct the mistake?
|
||||
Would you be willing to lie to a court for a close friend if it meant saving your friend from going to jail for life?
|
||||
Would you be willing to eat a bowl of crickets for 0,000?
|
||||
If you could have anyone locked in a room so that you could torment them for a day, whom would you choose ad how would you torment them?
|
||||
Do you feel that children should be sheltered from unhappiness?
|
||||
If you could have personally witnessed anything, what would you want to have seen?
|
||||
If you could wake up tomorrow in the body of someone else, who would you pick and what would you do?
|
||||
If you could be any age for a week, what age would that be?
|
||||
What question do you hate to answer?
|
||||
If you could only have one meal for the rest of your life, what would it be?
|
||||
Where do you go to get on a computer?
|
||||
How do you start a conversation?
|
||||
What keys on a keyboard do you not use?
|
||||
If you had a brainwashing machine, who would you use it on?
|
||||
You are walking home in the dark, you see something move. What/Who is it(guess)? What do you do?
|
||||
What is the strangest name someone has introduced themselves as to you? What is their real name?
|
||||
Where were you 3 hours ago? Do you think someone was stalking you?
|
||||
Have you ever eating a crayon, or glue? Or what strange thing have you eaten?
|
||||
What type of music do you listen to? (Genre, artists, songs?)
|
||||
What cheers you up?
|
||||
What do you constantly think about that, either makes you sad or just anything?
|
||||
Is there something you constantly lose at your hours or anywhere?
|
||||
Do you have a favorite book or read much? Why or why not?
|
||||
What is the longest you have gone without sleep?
|
||||
Do you have anyone you go to for advice? In person or online?
|
||||
What is the habit you are proudest of breaking or want to break?
|
||||
Is there anything I should know?
|
||||
What do you order or not order at a restaurant you have been to or never been to?
|
||||
What is your favorite word? Least favorite?
|
||||
Describe something that's happened to you for which had no explanation.
|
||||
What did you do for your latest birthday?
|
||||
What holidays do you celebrate? Are you a religious person or not?
|
||||
If you had to be named after a city, state, or country (etc), which would you want it to be?
|
||||
Who is your hero?
|
||||
Which do you use more often, the dictionary or the thesaurus?
|
||||
Have you ever been stung by a bee?
|
||||
Have you ever tipped a cow?
|
||||
What's the sickest you have ever been?
|
||||
Are you still learning who you are?
|
||||
Are you afraid of heights? Or what are you afraid of?
|
||||
Have you ever taken dance lessons? Who would you want to dance with?
|
||||
What is the most memorable class you have ever taken?
|
||||
Why?
|
||||
What's your favorite knock-knock joke?
|
||||
What is your favorite commercial?
|
||||
If you could spend the day with any celebrity, who would it be?
|
||||
What is your favorite breakfast food?
|
||||
Do you like guacamole? Have you ever been in a food fight?
|
||||
What is your favorite thing to spend money on?
|
||||
What is the weirdest thing about you? Are you proud of it?
|
||||
Ever been in love with 2 people at the same time? Do you think that's wrong?
|
||||
Ever had any relatives in jail?
|
||||
Glass half full or half empty? Or is the glass just malformed?
|
||||
Mountains or the beach? View, or the tv?
|
||||
Plain, train, or car? Boat, subway, or teleportation device?
|
||||
If you could retire tomorrow, what would you do?
|
||||
Ever sold/donated your blood? If you haven't do you want to?
|
||||
Crowds, small groups, or “Go away, I'm a loner”?
|
||||
Name the most terrifying moment of your life so far. Have you recovered from it?
|
||||
What famous person do people tell you that you most resemble?
|
||||
What is the strangest thing you have ever eaten?
|
||||
If you could bring any person back to life, who would it be?
|
||||
Do you believe honesty is the best policy?
|
||||
What dead person would you least want to be haunted by?
|
||||
Who would you most like to be stuck in an elevator with?
|
||||
Who would you least like to be .?
|
||||
What do you think Victoria's secret is?
|
||||
Which cartoon character do you resemble the most?
|
||||
Would you rather go a week without bathing, but be able to change your clothes? Or a week without changing your clothes but be able to bathe.
|
||||
Which of the four seasons do you most love? Or Hate?
|
||||
If you could choose your method of dying or where, what would they be?
|
||||
If you had to be trapped in a tv show for a month, which would you choose?
|
||||
List someone you know, and describe them in 5 words.
|
||||
You can select one person from history and have them truthfully answer one question, who would you select and what is the question?
|
||||
If you join the circus, what would you perform?
|
||||
Is there anything purple within 10 feet of you? What is it?
|
||||
When was the last time you bought something? What was it?
|
||||
Are you wearing socks right now?
|
||||
Have you been to the movies in the last 5 days?
|
||||
When was the last time you ran/went for a jog?
|
||||
Your dream vacation? Worst vacation? Best vacation?
|
||||
Worst injury you have had?
|
||||
Grab the book nearest to you, turn to page 18, and find line 4.
|
||||
Stretch your left arm out as far as you can, What can you touch?
|
||||
Before you started this survey, what were you doing?
|
||||
What is the last thing you watched on TV?
|
||||
Without looking, guess what time it is
|
||||
Now look at the clock. What is the actual time?
|
||||
With the exception of the computer, what can you hear?
|
||||
When did you last step outside? What were you doing?
|
||||
Did you dream last night?
|
||||
Do you remember your dreams?
|
||||
When did you last laugh?
|
||||
Do you remember why / at what?
|
||||
What is on the walls of the room you are in?
|
||||
Seen anything weird lately?
|
||||
What is the last film you saw?
|
||||
If you could live anywhere in the world, where would you live?
|
||||
If you became a multi-millionaire overnight, what would you buy?
|
||||
Tell me something about you that most people don't know.
|
||||
If you could change one thing about the world, regardless of guilt or politics, what would you do?
|
||||
Do you like to dance?
|
||||
Would you ever consider living abroad?
|
||||
Does your name make any interesting anagrams?
|
||||
Who made the last incoming call on your phone?
|
||||
What is the last thing you downloaded onto your computer?
|
||||
Last time you swam in a pool?
|
||||
Type of music you like most?
|
||||
Type of music you dislike most?
|
||||
Are you listening to music right now?
|
||||
What color is your bedroom carpet?
|
||||
If you could change something about your home, without worry about expense or mess, what would you do?
|
||||
What was the last thing you bought?
|
||||
Have you ever ridden on a motorbike?
|
||||
Would you go bungee jumping or sky diving?
|
||||
Do you have a garden?
|
||||
Do you really know all the words to your national anthem?
|
||||
What is the first thing you think of when you wake up in the morning?
|
||||
If you could eat lunch with one famous person, who would it be?
|
||||
Who sent the last text message you received?
|
||||
Which store would you choose to max out your credit card?
|
||||
What time is bed time?
|
||||
Have you ever been in a beauty pageant?
|
||||
How many tattoos do you have?
|
||||
If you don't have any, have you ever thought of getting one?
|
||||
What did you do for your last birthday?
|
||||
Do you carry a donor card?
|
||||
Who was the last person you ate dinner with?
|
||||
Is the glass half empty or half full?
|
||||
What's the farthest-away place you've been?
|
||||
When's the last time you ate a homegrown tomato?
|
||||
Have you ever won a trophy?
|
||||
Are you a good cook?
|
||||
Do you know how to pump your own gas?
|
||||
If you could meet any one person (from history or currently alive), who would it be?
|
||||
Have you ever had to wear a uniform to school?
|
||||
Do you touch-type?
|
||||
What's under your bed?
|
||||
Do you believe in love at first sight?
|
||||
Think fast, what do you like right now?
|
||||
Where were you on Valentine's day?
|
||||
What time do you get up?
|
||||
What was the name of your first pet?
|
||||
Who is the second to last person to call you?
|
||||
Is there anything going on this weekend?
|
||||
How are you feeling right now?
|
||||
What do you think about the most?
|
||||
What time do you get up in the morning?
|
||||
If you had A Big Win in the Lottery, how long would you wait to tell people?
|
||||
Who would you tell first?
|
||||
What is the last movie that you saw at the cinema?
|
||||
Do you sing in the shower?
|
||||
Which store would you choose to max out your credit card?
|
||||
What do you do most when you are bored?
|
||||
What do you do for a living?
|
||||
Do you love your job?
|
||||
What did you want to be when you grew up?
|
||||
If you could have any job, what would you want to do/be?
|
||||
Which came first the chicken or the egg?
|
||||
How many keys on your key ring?
|
||||
Where would you retire to?
|
||||
What kind of car do you drive?
|
||||
What are your best physical features?
|
||||
What are your best characteristics?
|
||||
If you could go anywhere in the world on vacation where would you go?
|
||||
What kind of books do you like to read?
|
||||
Where would you want to retire to?
|
||||
What is your favorite time of the day?
|
||||
Where did you grow up?
|
||||
How far away from your birthplace do you live now?
|
||||
What are you reading now?
|
||||
Are you a morning person or a night owl?
|
||||
Can you touch your nose with your tongue?
|
||||
Can you close your eyes and raise your eyebrows?
|
||||
Do you have pets?
|
||||
How many rings before you answer the phone?
|
||||
What is your best childhood memory?
|
||||
What are some of the different jobs that you have had in your life?
|
||||
Any new and exciting things that you would like to share?
|
||||
What is most important in life?
|
||||
What Inspires You?
|
||||
How lucky are you and why?
|
||||
If you were a pizza deliveryman how would you benefit from scissors?
|
||||
If you could sing one song on American Idol, what would it be?
|
||||
Are you more of a hunter or a gatherer?
|
||||
If you were on an island and could only bring 3 things, what would you bring?
|
||||
If you were a box of cereal, what would you be and why?
|
||||
Do you believe in Big Foot?
|
||||
Why is a tennis ball fuzzy?
|
||||
What is your least favorite thing about humanity?
|
||||
How honest are you?
|
||||
If you were 80 years old, what would you tell your children?
|
||||
You're a new addition to the crayon box, what color would you be and why?
|
||||
How does the internet work?
|
||||
If there was a movie produced about your life, who would play you, and why?
|
||||
What's the color of money?
|
||||
What was the last gift you gave someone?
|
||||
What is the funniest thing that has happened to you recently?
|
||||
Have you ever been on a boat?
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
nohup ./tilde_bot.py -s 127.0.0.1 -n tilde_bot -c \#bot_test >> log 2>> log &
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
nohup ./topicbot.py -s 127.0.0.1 -n topicbot -c \#tildetown >> log 2>> log &
|
||||
#nohup ./topicbot.py -s 127.0.0.1 -n topicbot -c \#bot_test >> log 2>> log &
|
||||
#./topic_bot.py -s 127.0.0.1 -n topic_bot -c \#bot_test
|
||||
Executable
+89
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/python
|
||||
# http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python
|
||||
|
||||
# Import some necessary libraries.
|
||||
import socket
|
||||
import os
|
||||
import sys
|
||||
from optparse import OptionParser
|
||||
|
||||
import get_users
|
||||
import mentions
|
||||
import formatter
|
||||
|
||||
parser = OptionParser()
|
||||
|
||||
parser.add_option("-s", "--server", dest="server", default='127.0.0.1',
|
||||
help="the server to connect to", metavar="SERVER")
|
||||
parser.add_option("-c", "--channel", dest="channel", default='#bot_test',
|
||||
help="the channel to join", metavar="CHANNEL")
|
||||
parser.add_option("-n", "--nick", dest="nick", default='tilde_bot',
|
||||
help="the nick to use", metavar="NICK")
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
def ping():
|
||||
ircsock.send("PONG :pingis\n")
|
||||
|
||||
def sendmsg(chan , msg):
|
||||
ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n")
|
||||
|
||||
def joinchan(chan):
|
||||
ircsock.send("JOIN "+ chan +"\n")
|
||||
|
||||
def hello():
|
||||
ircsock.send("PRIVMSG "+ channel +" :Hello!\n")
|
||||
|
||||
def tilde(channel, user, time):
|
||||
#h = os.popen("haiku").read().replace("\n", " // ")
|
||||
msg = time + ":" + user
|
||||
print msg
|
||||
ircsock.send("PRIVMSG "+ channel +" :" + msg + "\n")
|
||||
|
||||
def connect(server, channel, botnick):
|
||||
ircsock.connect((server, 6667))
|
||||
ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :This bot is a result of a tutoral covered on http://shellium.org/wiki.\n") # user authentication
|
||||
ircsock.send("NICK "+ botnick +"\n")
|
||||
|
||||
joinchan(channel)
|
||||
|
||||
def get_user_from_message(msg):
|
||||
try:
|
||||
i1 = msg.index(':') + 1
|
||||
i2 = msg.index('!')
|
||||
return msg[i1:i2]
|
||||
except ValueError:
|
||||
return ""
|
||||
|
||||
def listen():
|
||||
while 1:
|
||||
|
||||
ircmsg = ircsock.recv(2048)
|
||||
ircmsg = ircmsg.strip('\n\r')
|
||||
|
||||
if ircmsg.find("PING :") != -1:
|
||||
ping()
|
||||
|
||||
formatted = formatter.format_message(ircmsg)
|
||||
|
||||
if "" == formatted:
|
||||
continue
|
||||
|
||||
print formatted
|
||||
|
||||
split = formatted.split("\t")
|
||||
time = split[0]
|
||||
user = split[1]
|
||||
messageText = split[2]
|
||||
|
||||
if ircmsg.find(":!tilde") != -1:
|
||||
tilde(options.channel, user, time)
|
||||
|
||||
if ircmsg.find("PING :") != -1:
|
||||
ping()
|
||||
|
||||
sys.stdout.flush()
|
||||
|
||||
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
connect(options.server, options.channel, options.nick)
|
||||
listen()
|
||||
Executable
+187
@@ -0,0 +1,187 @@
|
||||
#!/usr/bin/python
|
||||
# http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python
|
||||
|
||||
# Import some necessary libraries.
|
||||
import socket
|
||||
import os
|
||||
import sys
|
||||
from optparse import OptionParser
|
||||
import fileinput
|
||||
import random
|
||||
|
||||
import formatter
|
||||
import get_users
|
||||
import mentions
|
||||
import pretty_date
|
||||
import inflect
|
||||
|
||||
parser = OptionParser()
|
||||
|
||||
parser.add_option("-s", "--server", dest="server", default='127.0.0.1',
|
||||
help="the server to connect to", metavar="SERVER")
|
||||
parser.add_option("-c", "--channel", dest="channel", default='#bot_test',
|
||||
help="the channel to join", metavar="CHANNEL")
|
||||
parser.add_option("-n", "--nick", dest="nick", default='topicbot',
|
||||
help="the nick to use", metavar="NICK")
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
p = inflect.engine()
|
||||
|
||||
def ping():
|
||||
ircsock.send("PONG :pingis\n")
|
||||
|
||||
def sendmsg(chan , msg):
|
||||
ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n")
|
||||
|
||||
def joinchan(chan):
|
||||
ircsock.send("JOIN "+ chan +"\n")
|
||||
|
||||
def hello():
|
||||
ircsock.send("PRIVMSG "+ channel +" :Hello!\n")
|
||||
|
||||
def get_topic(channel, user, time):
|
||||
#topic scores are saved as <USER>&^%<GETS SCORE>&^%<SETS SCORE>
|
||||
with open("topicscores.txt", "r") as scorefile:
|
||||
scores = scorefile.readlines()
|
||||
userscore = 1
|
||||
found = False
|
||||
with open("topicscores.txt", "w") as scorefile:
|
||||
for idx,score in enumerate(scores):
|
||||
data = score.strip("\n").split("&^%")
|
||||
if(data[0] == user):
|
||||
found = True
|
||||
userscore = int(data[1])+1
|
||||
scores[idx] = data[0] + "&^%" + str(userscore) + "&^%" + data[2] + "\n"
|
||||
scorefile.writelines(scores)
|
||||
if(not found):
|
||||
scorefile.write(user + "&^%1&^%0")
|
||||
|
||||
|
||||
with open("topics_" + channel + ".txt", "r") as topics:
|
||||
topic = topics.readlines()[-1].strip("\n").split("&^%", 3)
|
||||
ircsock.send("PRIVMSG "+ channel +" :I've told you " + p.number_to_words(userscore) + " times! It's \"" + topic[2] + "\" (Set by " + topic[1] + " " + pretty_date.pretty_date(int(topic[0])) + ")\n")
|
||||
|
||||
def count_topic(channel, user, time, msg):
|
||||
with open("topics_" + channel + ".txt", "a") as topics:
|
||||
topics.write(time + "&^%" + user + "&^%" + msg + "\n")
|
||||
with open("topicscores.txt", "r") as scorefile:
|
||||
scores = scorefile.readlines()
|
||||
userscore = 1
|
||||
found = False
|
||||
with open("topicscores.txt", "w") as scorefile:
|
||||
for idx,score in enumerate(scores):
|
||||
data = score.strip("\n").split("&^%")
|
||||
if(data[0] == user):
|
||||
found = True
|
||||
userscore = int(data[2])+1
|
||||
scores[idx] = data[0] + "&^%" + data[1] + "&^%" + str(userscore) + "\n"
|
||||
scorefile.writelines(scores)
|
||||
if(not found):
|
||||
scorefile.write(user + "&^%0&^%1")
|
||||
ircsock.send("PRIVMSG "+ channel +" :" + user + " has changed the topic " + p.number_to_words(userscore) + " times!\n")
|
||||
|
||||
def set_topic(channel, user, time, msg):
|
||||
ircsock.send("TOPIC "+ channel +" :" + msg + "\n")
|
||||
count_topic(channel, user, time, msg)
|
||||
|
||||
def random_topic(channel, user, time):
|
||||
with open("randomtopics.txt") as rtopics:
|
||||
msg = random.choice(rtopics.readlines()).strip("\n")
|
||||
set_topic(channel, user, time, msg)
|
||||
|
||||
def rollcall(channel):
|
||||
ircsock.send("PRIVMSG "+ channel +" :topicbot reporting! I respond to !topic !settopic !randomtopic !thistory\n")
|
||||
|
||||
def topic_score():
|
||||
ircsock.send("PRIVMSG "+ channel +" :Not implemented yet")
|
||||
|
||||
def topic_scores():
|
||||
ircsock.send("PRIVMSG "+ channel +" :Not implemented yet")
|
||||
|
||||
def topic_history(channel, user, count):
|
||||
try:
|
||||
iCount = int(count.split()[1])
|
||||
except ValueError:
|
||||
iCount = 3
|
||||
if(iCount > 10):
|
||||
iCount = 10
|
||||
if(iCount < 1):
|
||||
iCount = 3
|
||||
with open("topics_" + channel + ".txt", "r") as topicsfile:
|
||||
#topics = topicsfile.readlines()[-iCount:].reverse()
|
||||
ircsock.send("PRIVMSG "+ channel +" :Ok, here were the last " + p.number_to_words(iCount) + " topics\n")
|
||||
for idx,topic in enumerate(reversed(topicsfile.readlines()[-iCount:])):
|
||||
topic = topic.strip("\n").split("&^%", 3)
|
||||
ircsock.send("PRIVMSG "+ channel +" :" + str(idx+1) + ": \"" + topic[2] + "\" (Set by " + topic[1] + " " + pretty_date.pretty_date(int(topic[0])) + ")\n")
|
||||
|
||||
|
||||
def connect(server, channel, botnick):
|
||||
ircsock.connect((server, 6667))
|
||||
ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :This bot is a result of a tutoral covered on http://shellium.org/wiki.\n") # user authentication
|
||||
ircsock.send("NICK "+ botnick +"\n")
|
||||
|
||||
joinchan(channel)
|
||||
|
||||
def get_user_from_message(msg):
|
||||
try:
|
||||
i1 = msg.index(':') + 1
|
||||
i2 = msg.index('!')
|
||||
return msg[i1:i2]
|
||||
except ValueError:
|
||||
return ""
|
||||
|
||||
def listen():
|
||||
while 1:
|
||||
|
||||
ircmsg = ircsock.recv(2048)
|
||||
ircmsg = ircmsg.strip('\n\r')
|
||||
|
||||
if ircmsg.find("PING :") != -1:
|
||||
ping()
|
||||
|
||||
formatted = formatter.format_message(ircmsg)
|
||||
|
||||
if "" == formatted:
|
||||
continue
|
||||
|
||||
# print formatted
|
||||
|
||||
split = formatted.split("\t")
|
||||
time = split[0]
|
||||
user = split[1]
|
||||
command = split[2]
|
||||
channel = split[3]
|
||||
messageText = split[4]
|
||||
|
||||
if(command == "TOPIC" and user != options.nick):
|
||||
count_topic(channel,user, time, messageText)
|
||||
|
||||
if ircmsg.find(":!topic") != -1:
|
||||
get_topic(channel, user, time)
|
||||
|
||||
if ircmsg.find(":!settopic") != -1:
|
||||
set_topic(channel, user, time, messageText[10:])
|
||||
|
||||
if ircmsg.find(":!tscores") != -1:
|
||||
topic_scores()
|
||||
elif ircmsg.find(":!tscores") != -1:
|
||||
topic_score()
|
||||
|
||||
if ircmsg.find(":!randomtopic") != -1:
|
||||
random_topic(channel, user, time)
|
||||
|
||||
if ircmsg.find(":!thistory") != -1:
|
||||
topic_history(channel, user, messageText)
|
||||
|
||||
if ircmsg.find(":!rollcall") != -1:
|
||||
rollcall(channel)
|
||||
|
||||
if ircmsg.find("PING :") != -1:
|
||||
ping()
|
||||
|
||||
sys.stdout.flush()
|
||||
|
||||
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
connect(options.server, options.channel, options.nick)
|
||||
listen()
|
||||
Whitespace-only changes.
@@ -0,0 +1,5 @@
|
||||
krowbar&^%20&^%13
|
||||
um&^%11&^%8
|
||||
kc&^%0&^%10
|
||||
marcus&^%3&^%0
|
||||
khoi&^%1&^%0
|
||||
Reference in new issue
Block a user