Skip to content

Commit 61de262

Browse files
author
naveedm9
committed
Handle bad user input more gracefully when connecting to a group chat.
git-svn-id: http://vimchat.googlecode.com/svn/trunk@120 d1d492a2-f496-11dd-9d1d-173cc1d06e3c
1 parent 944071f commit 61de262

File tree

1 file changed

+49
-38
lines changed

1 file changed

+49
-38
lines changed

plugin/vimchat.vim

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,9 +1116,22 @@ class VimChatScope:
11161116
def openGroupChat(self):
11171117
accounts = self.showAccountList()
11181118

1119-
account = accounts[int(vim.eval(
1120-
'input("Account (enter the number from the above list): ")'))]
1119+
input = vim.eval(
1120+
'input("Account (enter the number from the above list): ")')
1121+
if not re.match(r'\d+$', input):
1122+
vim.command('echohl ErrorMsg')
1123+
vim.command('echo "\\nYou must enter an integer corresponding'
1124+
+ ' to an account."')
1125+
vim.command('echohl None')
1126+
return
1127+
index = int(input)
1128+
if index < 0 or index >= len(accounts):
1129+
vim.command('echohl ErrorMsg')
1130+
vim.command(r'echo "\nInvalid account number. Try again."')
1131+
vim.command('echohl None')
1132+
return
11211133

1134+
account = accounts[index]
11221135
chatroom = vim.eval('input("Chat Room to join: ")')
11231136
name = vim.eval('input("Name to Use: ")')
11241137
self.groupChatNames.append(name)
@@ -1141,42 +1154,6 @@ class VimChatScope:
11411154
return accounts
11421155
#}}}
11431156

1144-
#NOTIFY
1145-
#{{{ notify
1146-
def notify(self, jid, msg, groupChat):
1147-
# Important to keep this print statement. As a side effect, it
1148-
# refreshes the buffer so the new message shows up.
1149-
print "Message Received from: " + jid
1150-
1151-
if groupChat:
1152-
myNames = map(lambda x: x.split('@')[0], self.accounts.keys())
1153-
myNames.extend(self.groupChatNames)
1154-
foundMyName = False
1155-
for name in myNames:
1156-
if name in msg:
1157-
foundMyName = True
1158-
break
1159-
if not foundMyName:
1160-
return
1161-
1162-
vim.command("set tabline=%#Error#New-message-from-" + jid);
1163-
1164-
if pynotify_enabled and 'DBUS_SESSION_BUS_ADDRESS' in os.environ:
1165-
pynotify.init('vimchat')
1166-
n = pynotify.Notification(jid + ' says: ', msg, 'dialog-warning')
1167-
n.set_timeout(10000)
1168-
n.show()
1169-
1170-
if gtk_enabled:
1171-
self.statusIcon.blink(True)
1172-
#}}}
1173-
#{{{ clearNotify
1174-
def clearNotify(self):
1175-
vim.command('set tabline&')
1176-
if gtk_enabled:
1177-
self.statusIcon.blink(False)
1178-
#}}}
1179-
11801157
#LOGGING
11811158
#{{{ log
11821159
def log(self, account, user, msg):
@@ -1348,6 +1325,40 @@ class VimChatScope:
13481325
# Notify
13491326
self.notify(jid, message, groupChat)
13501327
#}}}
1328+
#{{{ notify
1329+
def notify(self, jid, msg, groupChat):
1330+
# Important to keep this print statement. As a side effect, it
1331+
# refreshes the buffer so the new message shows up.
1332+
print "Message Received from: " + jid
1333+
1334+
if groupChat:
1335+
myNames = map(lambda x: x.split('@')[0], self.accounts.keys())
1336+
myNames.extend(self.groupChatNames)
1337+
foundMyName = False
1338+
for name in myNames:
1339+
if name in msg:
1340+
foundMyName = True
1341+
break
1342+
if not foundMyName:
1343+
return
1344+
1345+
vim.command("set tabline=%#Error#New-message-from-" + jid);
1346+
1347+
if pynotify_enabled and 'DBUS_SESSION_BUS_ADDRESS' in os.environ:
1348+
pynotify.init('vimchat')
1349+
n = pynotify.Notification(jid + ' says: ', msg, 'dialog-warning')
1350+
n.set_timeout(10000)
1351+
n.show()
1352+
1353+
if gtk_enabled:
1354+
self.statusIcon.blink(True)
1355+
#}}}
1356+
#{{{ clearNotify
1357+
def clearNotify(self):
1358+
vim.command('set tabline&')
1359+
if gtk_enabled:
1360+
self.statusIcon.blink(False)
1361+
#}}}
13511362

13521363
#OTR
13531364
#{{{ otrVerifyBuddy

0 commit comments

Comments
 (0)