forked from JamezQ/u413lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQbot2.py
More file actions
130 lines (123 loc) · 3.4 KB
/
Qbot2.py
File metadata and controls
130 lines (123 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Qbot2.py
#
# Copyright 2011 James McClain <jamezmcclain@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
# TODO ###########################
#
# LISTING WHAT I HAVE PLANNED:
# option tags "-f, -x", piping !|, evaluation, chat logging and statistics.
# Commands that are planned:
# !say !fortune !qfortune !vote !poll !uno !cleverbot !welcome
# !roll !spin !google !spelz !copy !werewolf !connect4 !holdem !blackjack
#
##################################
import u413lib
import time
import random
CK = '@'
laioni = False
def Command(data):
test_data = data.split(' ')
if test_data[0][0] == CK:
if len(test_data) > 1:
return {'Command': test_data[0][1:].lower(),'Args': ' '.join(test_data[1:])}
else:
return {'Command': test_data[0][1:].lower(),'Args': False}
else:
return {'Command': False,'Args': False}
def laioni_mode(old_string):
to_mix = old_string.split(' ')
mixed = ""
for string in to_mix:
if len(string) > 3:
mix = string[1:-1]
mix = list(mix)
random.shuffle(mix)
mix = ''.join(mix)
string = string[0]+mix+string[-1]
mixed += string+" "
elif len(string) == 3:
mix = string[1:]
mix = list(mix)
random.shuffle(mix)
mix = ''.join(mix)
string = string[0]+mix
mixed += string+" "
else:
mix = string
mix = list(mix)
random.shuffle(mix)
mix = ''.join(mix)
string = mix
mixed += string+" "
return mixed[:-1]
def send(string):
global chat
if laioni:
string = laioni_mode(string)
chat.send(string)
else:
chat.send(string)
def main():
global laioni
global chat
client = u413lib.createclient()
if not client.login('USER','PASS'):
exit()
chat = client.joinchat('general')
client.sendRawCommand('channel general')
while True:
chatget = chat.get()
if chatget:
for text in chatget:
if text['Type'] == 'Message':
command = Command(text['Msg'])
if command['Command'] == 'say':
if command['Args']:
print repr(command['Args'])
send(command['Args'])
elif command['Command'] == 'hw':
if command['Args']:
send('hw args')
else:
string = 'Hello World!'
for i in range(len(string)+1):
send(string[0:i])
elif command['Command'] == 'roll':
if command['Args']:
pass
else:
num = random.choice(range(100))
send(str(num))
elif command['Command'] == 'laioni':
if command['Args']:
pass
else:
if laioni:
laioni = False
send("Laioni mode switched off")
else:
send("Laioni mode switched on")
laioni = True
print text['User'],text['Msg'],text['Timestamp']
time.sleep(7)
return 0
if __name__ == '__main__':
main()