This repository has been archived by the owner on Sep 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.py
executable file
·121 lines (103 loc) · 3.79 KB
/
console.py
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
########################################
## Adventure Bot "Dennis" ##
## console.py ##
## Copyright 2012-2013 PariahSoft LLC ##
########################################
## **********
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to
## deal in the Software without restriction, including without limitation the
## rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
## sell copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in
## all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
## IN THE SOFTWARE.
## **********
####################
# Console Handling #
####################
import socket, string, time
from database import get
from helpers import *
### Command Imports ###
from commands.help import C_HELP, help_entries
from commands.version import C_VERSION, version_info
from commands.join import C_JOIN
from commands.quit import C_QUIT
from commands.say import C_SAY
from commands.shout import C_SHOUT
from commands.roll import C_ROLL
from commands.me import C_ME
from commands.look import C_LOOK
from commands.go import C_GO
from commands.list import C_LIST
from commands.self import C_SELF
from commands.mkroom import C_MKROOM
from commands.room import C_ROOM
from commands.exit import C_EXIT
from commands.mkitem import C_MKITEM
from commands.item import C_ITEM
from commands.tp import C_TP
### Command Hooks ###
CH_OFFLINE = { # Offline Commands
"help": C_HELP,
"version": C_VERSION,
"join": C_JOIN
}
CH_ONLINE = { # Online Commands
"quit": C_QUIT,
"say": C_SAY,
"shout": C_SHOUT,
"roll": C_ROLL,
"me": C_ME,
"look": C_LOOK,
"go": C_GO,
"list": C_LIST,
"self": C_SELF,
"mkroom": C_MKROOM,
"room": C_ROOM,
"exit": C_EXIT,
"mkitem": C_MKITEM,
"item": C_ITEM,
"tp": C_TP
}
### Console Input Processor ###
def process(S, DB, line, nick):
global info
for char in line:
if not char in string.printable: # Ignore weird characters.
line = line.replace(char, "")
complete = line[1:].split(':',1) # Split message into sections
info = complete[0].split(' ') # Pieces of message
try:
info[1]
msgpart=complete[1].rstrip()
except IndexError: # Fake line
return
sender = info[0].split('!')[0] # Sender info
if info[1].lower() == "quit": # Did a player leave IRC?
rows = get(DB, "SELECT username FROM players WHERE online='1'")
for player in rows:
if player[0] == sender.lower():
C_QUIT(S, DB, sender, [])
break
if len(msgpart) > 0 and len(info) >= 3 and info[1].lower() == "privmsg" and info[2].lower() == nick.lower(): # Commands
cmd = msgpart.rstrip().split(' ')
if cmd[0].lower() != "join":
print "[{0}] <{1}> :: {2}".format(int(time.time()), sender, msgpart.rstrip())
if cmd[0].lower() in CH_OFFLINE: # Offline Commands
CH_OFFLINE[cmd[0].lower()](S, DB, sender.lower(), cmd[1:])
elif online(DB, sender.lower()): # Online Commands
if cmd[0].lower() in CH_ONLINE:
CH_ONLINE[cmd[0].lower()](S, DB, sender.lower(), cmd[1:])
else:
send(S, sender, "No such command or you must join first.")