Syntax: Select all
import es, cmdlib, random, playerlib, os, path, pickle, popuplib
from configobj import ConfigObj
s_info = es.AddonInfo()
s_info.name = 'ChatBot'
s_info.author = 'Stirni'
s_info.version = '1.0'
s_info.describtion = 'This is a Chat Bot for CS:S written by Stirni'
s_basepath = path.path(str(__file__)).dirname().replace(os.sep, '/')
s_basename = s_basepath.split('/')[(-1)]
s_info.basename = s_basename
s_noans_file = s_basepath + '/stirni_bot_noanswers.db'
s_responses_file = s_basepath + '/stirni_bot_brain.db'
s_responses = {}
s_noans = []
s_bot = 0
s_uid = 0
s_cl = ConfigObj(s_basepath + '/stirni_chat_bot.cfg')
s_bot_fullname = s_cl['s_bot_fullname']
s_bot_shortname = s_cl['s_bot_shortname']
s_bot_specname = s_cl['s_bot_specname']
s_admins = s_cl['s_admins'].replace(' ', '').split(',')
s_bot_vname = s_cl['s_bot_vname']
s_greeting = s_cl['s_greeting'].replace(' ', '').split(',')
s_bye = s_cl['s_bye'].replace(' ', '').split(',')
s_love = s_cl['s_love'].replace(' ', '').split(',')
def load():
msg('loaded!')
es.addons.registerSayFilter(s_bot_sayfilter)
s_get_noans()
s_get_responses()
if es.exists('saycommand', '!learn'):
es.unregsaycmd('!learn')
cmdlib.registerSayCommand('!learn', s_learn, '')
if es.exists('clientcommand', '!learn'):
es.unregclientcmd('!learn')
cmdlib.registerClientCommand('!learn', s_learn, '')
if es.exists('saycommand', '!knows'):
es.unregsaycmd('!knows')
cmdlib.registerSayCommand('!knows', s_loadyes, '')
if es.exists('clientcommand', '!knows'):
es.unregclientcmd('!knows')
cmdlib.registerClientCommand('!knows', s_loadyes, '')
if es.exists('saycommand', '!dknows'):
es.unregsaycmd('!dknows')
cmdlib.registerSayCommand('!dknows', s_loadno, '')
if es.exists('clientcommand', '!dknows'):
es.unregclientcmd('!dknows')
cmdlib.registerClientCommand('!dknows', s_loadno, '')
if es.exists('saycommand', '!clear'):
es.unregsaycmd('!clear')
cmdlib.registerSayCommand('!clear', s_clear, '')
if es.exists('clientcommand', '!clear'):
es.unregclientcmd('!clear')
cmdlib.registerClientCommand('!clear', s_clear, '')
if es.exists('saycommand', '!bsay'):
es.unregsaycmd('!bsay')
cmdlib.registerSayCommand('!bsay', s_bsay, '')
if es.exists('clientcommand', '!bsay'):
es.unregclientcmd('!bsay')
cmdlib.registerClientCommand('!bsay', s_bsay, '')
if es.exists('saycommand', '!save'):
es.unregsaycmd('!save')
cmdlib.registerSayCommand('!save', s_save_all, '')
if es.exists('clientcommand', '!save'):
es.unregclientcmd('!save')
cmdlib.registerClientCommand('!save', s_save_all, '')
if es.exists('clientcommand', '!unlearn'):
es.unregclientcmd('!unlearn')
cmdlib.registerClientCommand('!unlearn', s_unlearn, '')
def unload():
msg('unloaded!')
es.addons.unregisterSayFilter(s_bot_sayfilter)
s_save_noans()
s_save_responses()
def s_dontknow(name):
ran = random.randint(1, 5)
if ran == 1:
botmsg(name, 'Say that again?!')
elif ran == 2:
botmsg(name, 'Do you think I know all the answers?')
elif ran == 3:
botmsg(name, 'I dont know what to say to that!')
elif ran == 4:
botmsg(name, 'Im not here for your entertainment!')
elif ran == 5:
botmsg(name, 'This is not the time for that!')
def s_learn(userid, args):
global s_responses
steamid = es.getplayersteamid(userid)
name = es.getplayername(userid)
if steamid in s_admins:
if args:
args = str(args)
sa = args.split()
if len(sa) == 2:
if sa[0] not in list(s_responses.keys()):
s_responses[sa[0]] = []
s_responses[sa[0]].append(sa[1].replace('_', ' '))
botmsg(name, ' You did add %s with %s' % (sa[0], sa[1].replace('_', ' ')))
else:
tell(userid, 'The BOT must have exactly 2 arguments. Use _ if you want to have spaces')
else:
tell(userid, 'The BOT must have exactly 2 arguments. Use _ if you want to have spaces')
else:
tell(userid, 'The BOT only learns from admins!')
def s_loadyes(userid, args):
steamid = es.getplayersteamid(userid)
if steamid in s_admins:
if popuplib.exists('stirni_anse'):
popuplib.delete('stirni_anse')
stirni_any = popuplib.easylist('stirni_anse')
stirni_any.settitle('Words %s does know!' % s_bot_shortname)
for x in s_responses:
stirni_any.additem(x)
stirni_any.send(userid)
def s_loadno(userid, args):
global s_noans
steamid = es.getplayersteamid(userid)
if steamid in s_admins:
if popuplib.exists('stirni_noan'):
popuplib.delete('stirni_noan')
stirni_noa = popuplib.easylist('stirni_noan')
stirni_noa.settitle('Words %s doesnt know!' % s_bot_shortname)
for x in s_noans:
stirni_noa.additem(x)
stirni_noa.send(userid)
def s_clear(userid, args):
global s_responses
steamid = es.getplayersteamid(userid)
if steamid in s_admins:
del s_noans[:]
s_responses = {}
tell(userid, 'Cleared successfully')
def s_bsay(userid, args):
steamid = es.getplayersteamid(userid)
if steamid in s_admins:
if args:
es.msg('#multi', '%s #default%s' % (s_bot_vname, args))
def s_unlearn(userid, args):
steamid = es.getplayersteamid(userid)
if steamid in s_admins:
pass
def s_bot_sayfilter(userid, text, teamonly):
name = es.getplayername(userid)
response = 0
if text.lower().find(s_bot_shortname) >= 0 or text.lower().find(s_bot_fullname) >= 0:
if response == 0:
for re in s_responses:
if text.lower().find(re.lower()) >= 0:
es.msg('#multi', '%s #default%s, %s' % (s_bot_vname, name, random.choice(s_responses[re])))
response = 1
break
if response == 0:
for hi in s_greeting:
if text.lower().find(hi.lower()) >= 0:
es.msg('#multi', '%s #default%s %s' % (s_bot_vname, random.choice(s_greeting), name))
response = 1
break
if response == 0:
for by in s_bye:
if text.lower().find(by.lower()) >= 0:
es.msg('#multi', '%s #default%s %s' % (s_bot_vname, random.choice(s_bye), name))
response = 1
break
if response == 0:
for lo in s_love:
if text.lower().find(lo.lower()) >= 0:
es.msg('#multi', '%s #default I %s u too %s' % (s_bot_vname, random.choice(s_love), name))
response = 1
break
if response == 0:
s_noans.append(text)
s_dontknow(name)
elif text.lower().find('!rock') >= 0:
ran = random.randint(1, 3)
if ran == 1:
botmsg(name, 'You win! I lose with Scissors!')
elif ran == 2:
botmsg(name, 'You lose! I win with Paper!')
elif ran == 3:
botmsg(name, 'We tie! With Rock!')
elif text.lower().find('!paper') >= 0:
ran = random.randint(1, 3)
if ran == 1:
botmsg(name, 'You lose! I Win with Scissors!')
elif ran == 2:
botmsg(name, 'We tie! With Paper!')
elif ran == 3:
botmsg(name, 'You win! I lose with Rock!')
elif text.lower().find('!scissors') >= 0:
ran = random.randint(1, 3)
if ran == 1:
botmsg(name, 'We tie! With Scissors!')
elif ran == 2:
botmsg(name, 'You win! I Lose with Paper!')
elif ran == 3:
botmsg(name, 'You lose! I win With Rock!')
elif text.lower().find('!ip') >= 0:
botmsg(name, 'Your IP is %s!' % playerlib.getPlayer(userid).attributes['address'])
elif text.lower().find('!ping') >= 0:
botmsg(name, 'Your Ping is %s!' % playerlib.getPlayer(userid).attributes['ping'])
return (userid, text, teamonly)
def s_save_all(userid, args):
steamid = es.getplayersteamid(userid)
if steamid in s_admins:
s_save_responses()
s_save_noans()
tell(userid, 'Saved successfully')
def s_get_responses():
global s_responses
if os.path.isfile(s_responses_file):
s_file = open(s_responses_file)
s_responses = pickle.load(s_file)
s_file.close()
def s_save_responses():
s_file = open(s_responses_file, 'w')
pickle.dump(s_responses, s_file)
s_file.close()
def s_get_noans():
global s_noans
if os.path.isfile(s_noans_file):
s_file = open(s_noans_file)
s_noans = pickle.load(s_file)
s_file.close()
def s_save_noans():
s_file = open(s_noans_file, 'w')
pickle.dump(s_noans, s_file)
s_file.close()
def round_start(event_var):
global s_bot
if s_bot == 0:
pl = playerlib.getPlayerList('#all')
for p in pl:
if p.get('name') == s_bot_specname:
s_bot = 1
if s_bot == 0:
es.createbot(s_uid, s_bot_specname)
def es_map_start(event_var):
global s_bot
s_bot = 0
s_save_noans()
s_save_responses()
def botmsg(playername, text):
es.msg('#multi', '%s #default%s, %s' % (s_bot_vname, playername, text))
def msg(text):
es.msg('#multi', '#green[%s %s]#lightgreen %s' % (s_info.name, s_info.author, text))
def tell(userid, text):
es.tell(userid, '#multi', '#green[%s %s]#lightgreen %s' % (s_info.name, s_info.author, text))
CFG
Code: Select all
#####################
#### © by Stirni ####
#####################
# This is a chat plugin for Counter-Strike: Source
# This plugin is licensed under http://creativecommons.org/licenses/by-nc-nd/3.0/de/
#####################
#### © by Stirni ####
#####################
# NOTE: The originally ChatBot was made by DHack. Thanks to him
# because without him I could never have done this updated one.
# ===============================
# >> SETTINGS START
# ===============================
# It's allowed to edit until SETTINGS END.
# The bot will only respond to the bot's full name and to his short name.
# The Bot's (full) name
s_bot_fullname = 'Carl bot'
# The Bot's short name
# ! This MUST be lowercase !
s_bot_shortname = 'carl'
# The Bot's name when in Spectator
s_bot_specname = '[CONSOLE Carl]'
# Admins who can teach the bot something
# Seperate them with a ,
s_admins = 'STEAM_0:1:15559696, STEAM_ID_LAN'
# IF YOU KNOW WHAT YOU DO, YOU CAN TOUCH THIS:
# Chat output beginning
s_bot_vname = '#green[#lightgreenCONSOLE Carl#green]'
# Default knowlegdes: on greeting ; on saying goodbye ; on loving :)
# Seperate them with a ,
s_greeting = 'Hey, Hello, Hi, Sup, Welcome'
s_bye = 'Bye, GoodBye, Peace, Later, Night'
s_love = '<3, Love, ♥'
s_salut = 'Salut, Bonjour, Bienvenue'
s_bonjour = 'Salut, Bonjour, Bienvenue'
s_au revoir = 'Au revoir, au revoir pour le moment, Peace, a Plus tard, '
s_je taime = 'je t'aime ♥,
s_conard = 'les robot on aussi le droit au respect,
# ===============================
# >> SETTINGS END
# ===============================
#####################
#### © by Stirni ####
#####################