stirni_chat_bot evescriscrip

A place for requesting new Source.Python plugins to be made for your server.

Please request only one plugin per thread.
cut-magic
Junior Member
Posts: 19
Joined: Thu Jan 12, 2023 7:16 am

stirni_chat_bot evescriscrip

Postby cut-magic » Wed Jan 25, 2023 8:48 pm

this plugin is a chatbot capable of learning automatically which can sometimes cause inconvenience if you have troll players but in the worst case an admin can rectify the bot and it is fun but which can be practical with is that if a player makes an order to work for example a! wcs the bot will be able to tell him to do it without if we rule it in cfg I would really like to see this plugin again but unlike the real evenscript the emulator cannot not used PICKLE I tried to convert it with the ese convert command but I can't use it


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 ####
#####################
Last edited by Kami on Mon Jan 30, 2023 11:08 am, edited 1 time in total.
Reason: changed code to python highlighting
cut-magic
Junior Member
Posts: 19
Joined: Thu Jan 12, 2023 7:16 am

Re: stirni_chat_bot evescriscrip

Postby cut-magic » Sat Jan 28, 2023 9:16 am

would someone be able to put this evenscript plugin on python for me? it is for couter strike source I would really like to reuse it I had it in the past but as the emulator cannot use PICKLE
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: stirni_chat_bot evescriscrip

Postby cssbestrpg » Sat Jan 28, 2023 11:15 am

I can code it Source.Python, i try make it by today
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: stirni_chat_bot evescriscrip

Postby cssbestrpg » Sat Jan 28, 2023 9:06 pm

Here it is made to Source.Python, but i didn't test it at all

Syntax: Select all

import random, pickle, os, path
from configobj import ConfigObj
from events import Event
from players.entity import Player
from commands.say import SayCommand, SayFilter
from commands.client import ClientCommand
from menus import PagedMenu, PagedOption
from messages import SayText2
from colors import GREEN, LIGHT_GREEN
from listeners import OnLevelInit
from filters.players import PlayerIter
from engines.server import engine_server

s_basepath = path.Path(str(__file__)).dirname().replace(os.sep, '/')
s_basename = s_basepath.split('/')[(-1)]
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(',')

@Event('round_start')
def round_start(args):
global s_bot
if s_bot == 0:
for player in PlayerIter('all'):
if player.name == s_bot_specname:
s_bot = 1
if s_bot == 0:
engine_server.create_fake_client(f'{s_bot_specname}')

@OnLevelInit
def map_start(map):
global s_bot
s_bot = 0
s_save_noans()
s_save_responses()

@SayFilter
def say_filter(command, index, teamonly):
if index and command:
name = Player(index).name
text = command[0].lower()
response = 0
if text.lower() in s_bot_shortname or text.lower() in s_bot_fullname:
if response == 0:
for re in s_responses:
if text.lower() in re.lower():
SayText2(f'{GREEN}{s_bot_vname} \x01{name} {random.choice(s_responses[re])}').send()
response = 1
break

if response == 0:
for hi in s_greeting:
if text.lower() in hi.lower():
SayText2(f'{GREEN}{s_bot_vname} \x01{random.choice(s_greeting)} {name}').send()
response = 1
break

if response == 0:
for by in s_bye:
if text.lower() in by.lower():
SayText2(f'{GREEN}{s_bot_vname} \x01{random.choice(s_bye)} {name}').send()
response = 1
break

if response == 0:
for lo in s_love:
if text.lower() in low.lower():
SayText2(f'{GREEN}{s_bot_vname} \x01{random.choice(_slove)} {name}').send()
response = 1
break

if response == 0:
s_noans.append(text)
s_dontknow(name)

elif text == '!rock':
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 == '!paper':
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 == '!scissors':
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!')

@ClientCommand('!unlearn')
@SayCommand('!unlearn')
def unlearn_command(command, index, teamonly=False):
pass

@ClientCommand('!save')
@SayCommand('!save')
def save_command(command, index, teamonly=False):
steamid = Player(index).steamid
if steamid in s_admins:
s_save_responses()
s_save_noans()
tell(index, 'Saved successfully')

@ClientCommand('!bsay')
@SayCommand('!bsay')
def bsay_command(command, index, teamonly=False):
steamid = Player(index).steamid
args = command.arg_string
if steamid in s_admins:
if args:
SayText2(f'{GREEN}{s_bot_vname} \x01{args}').send()

@ClientCommand('!clear')
@SayCommand('!clear')
def clear_command(command, index, teamonly=False):
global s_responses
steamid = Player(index).steamid
if steamid in s_admins:
del s_noans[:]
s_responses = {}
tell(index, 'Cleared successfully')

@ClientCommand('!dknows')
@SayCommand('!dknows')
def no_knows_command(command, index, teamonly=False):
global s_noans
steamid = Player(index).steamid
if steamid in s_admins:
menu = PagedMenu(title=f'Words {s_bot_shortname} doesnt know!')
for x in s_noans:
menu.append(PagedOption(f'{x}', x))
menu.send(index)

@ClientCommand('!knows')
@SayCommand('!knows')
def knows_command(command, index, teamonly=False):
player = Player(index)
steamid = player.steamid
if steamid in s_admins:
menu = PagedMenu(title=f'Words {s_bot_shortname} does know!')
for x in s_responses:
menu.append(PagedOption(f'{x}', x))
menu.send(index)

@ClientCommand('!learn')
@SayCommand('!learn')
def learn_command(command, index, teamonly=False):
global s_responses
player = Player(index)
args = command.arg_string

steamid = player.steamid
name = player.name
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(index, 'The BOT must have exactly 2 arguments. Use _ if you want to have spaces')
else:
tell(index, 'The BOT must have exactly 2 arguments. Use _ if you want to have spaces')
else:
tell(index, 'The BOT only learns from admins!')

def botmsg(playername, text):
SayText2(f'{GREEN}{s_bot_vname} \x01{playername} {text}').send()

def tell(index, text):
SayText2(f'{GREEN}[ChatBot] Stirni{LIGHT_GREEN} {text}').send(index)

def load():
s_get_noans()
s_get_responses()

def unload():
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_get_responses():
global s_responses
if os.path.isfile(s_responses_file):
with open(s_responses_file) as s_file:
s_responses = pickle.load(s_file)

def s_save_responses():
with open(s_responses_file, 'w') as s_file:
pickle.dump(s_responses, s_file)

def s_get_noans():
global s_noans
if os.path.isfile(s_noans_file):
with open(s_noans_file) as s_file:
s_noans = pickle.load(s_file)

def s_save_noans():
with open(s_noans_file, 'w') as s_file:
pickle.dump(s_noans, s_file)


Edit: Added missing s_dontknow(name) function
Last edited by cssbestrpg on Sun Jan 29, 2023 10:56 am, edited 1 time in total.
cut-magic
Junior Member
Posts: 19
Joined: Thu Jan 12, 2023 7:16 am

Re: stirni_chat_bot evescriscrip

Postby cut-magic » Sun Jan 29, 2023 10:00 am

I did the tests for you on counter strike source but I have the impression that your code speaks of PIKLE but I thought it had been deleted then pyton source and also the evenscript emulator



2023-01-29 10:57:56 - sp.core.command - MESSAGE [SP] Chargement du plugin 'stirni_chat_bot'...
2023-01-29 10:57:56 - sp.hooks.exceptions - EXCEPTION [Source.Python]
[SP] Une erreur s'est produite:
Traceback (most recent call last):
File "..\addons\source-python\packages\source-python\plugins\command.py", line 164, in load_plugin
plugin = self.manager.load(plugin_name)
File "..\addons\source-python\packages\source-python\plugins\manager.py", line 207, in load
plugin._load()
File "..\addons\source-python\packages\source-python\plugins\instance.py", line 74, in _load
self.module = import_module(self.import_name)
File "..\addons\source-python\plugins\stirni_chat_bot\stirni_chat_bot.py", line 22, in <module>
s_cl = ConfigObj(s_basepath + '/stirni_chat_bot.cfg')
File "..\addons\source-python\packages\site-packages\configobj.py", line 1229, in __init__
self._load(infile, configspec)
File "..\addons\source-python\packages\site-packages\configobj.py", line 1318, in _load
raise error
File "<string>", line None

configobj.ConfigObjError: Parsing failed with several errors.
First error at line 49.


2023-01-29 10:57:56 - sp.core.command - MESSAGE [SP] Impossible de charger le plugin 'stirni_chat_bot'.
2023-01-29 10:58:11 - sp.core.command - MESSAGE [SP] Chargement du plugin 'stirni_chat_bot'...
2023-01-29 10:58:11 - sp.hooks.exceptions - EXCEPTION [Source.Python]
[SP] Une erreur s'est produite:
Traceback (most recent call last):
File "..\addons\source-python\packages\source-python\plugins\command.py", line 164, in load_plugin
plugin = self.manager.load(plugin_name)
File "..\addons\source-python\packages\source-python\plugins\manager.py", line 207, in load
plugin._load()
File "..\addons\source-python\packages\source-python\plugins\instance.py", line 74, in _load
self.module = import_module(self.import_name)
File "..\addons\source-python\plugins\stirni_chat_bot\stirni_chat_bot.py", line 22, in <module>
s_cl = ConfigObj(s_basepath + '/stirni_chat_bot.cfg')
File "..\addons\source-python\packages\site-packages\configobj.py", line 1229, in __init__
self._load(infile, configspec)
File "..\addons\source-python\packages\site-packages\configobj.py", line 1318, in _load
raise error
File "<string>", line None

configobj.ConfigObjError: Parsing failed with several errors.
First error at line 49.


2023-01-29 10:58:11 - sp.core.command - MESSAGE [SP] Impossible de charger le plugin 'stirni_chat_bot'.
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: stirni_chat_bot evescriscrip

Postby Kami » Sun Jan 29, 2023 10:40 am

SourcePython and the emulator can use pickle with no problems, the code just had some errors (I guess due to the changes from python versions)

You can try this version for the emulator:

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) == 3:
if sa[1] not in list(s_responses.keys()):
s_responses[sa[1]] = []
s_responses[sa[1]].append(sa[2].replace('_', ' '))
botmsg(name, ' You did add %s with %s' % (sa[1], sa[2].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, 'rb')
s_responses = pickle.load(s_file)
s_file.close()


def s_save_responses():
s_file = open(s_responses_file, 'wb')
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, 'rb')
s_noans = pickle.load(s_file)
s_file.close()


def s_save_noans():
s_file = open(s_noans_file, 'wb')
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_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))
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: stirni_chat_bot evescriscrip

Postby cssbestrpg » Sun Jan 29, 2023 10:49 am

cut-magic wrote:I did the tests for you on counter strike source but I have the impression that your code speaks of PIKLE but I thought it had been deleted then pyton source and also the evenscript emulator



2023-01-29 10:57:56 - sp.core.command - MESSAGE [SP] Chargement du plugin 'stirni_chat_bot'...
2023-01-29 10:57:56 - sp.hooks.exceptions - EXCEPTION [Source.Python]
[SP] Une erreur s'est produite:
Traceback (most recent call last):
File "..\addons\source-python\packages\source-python\plugins\command.py", line 164, in load_plugin
plugin = self.manager.load(plugin_name)
File "..\addons\source-python\packages\source-python\plugins\manager.py", line 207, in load
plugin._load()
File "..\addons\source-python\packages\source-python\plugins\instance.py", line 74, in _load
self.module = import_module(self.import_name)
File "..\addons\source-python\plugins\stirni_chat_bot\stirni_chat_bot.py", line 22, in <module>
s_cl = ConfigObj(s_basepath + '/stirni_chat_bot.cfg')
File "..\addons\source-python\packages\site-packages\configobj.py", line 1229, in __init__
self._load(infile, configspec)
File "..\addons\source-python\packages\site-packages\configobj.py", line 1318, in _load
raise error
File "<string>", line None

configobj.ConfigObjError: Parsing failed with several errors.
First error at line 49.


2023-01-29 10:57:56 - sp.core.command - MESSAGE [SP] Impossible de charger le plugin 'stirni_chat_bot'.
2023-01-29 10:58:11 - sp.core.command - MESSAGE [SP] Chargement du plugin 'stirni_chat_bot'...
2023-01-29 10:58:11 - sp.hooks.exceptions - EXCEPTION [Source.Python]
[SP] Une erreur s'est produite:
Traceback (most recent call last):
File "..\addons\source-python\packages\source-python\plugins\command.py", line 164, in load_plugin
plugin = self.manager.load(plugin_name)
File "..\addons\source-python\packages\source-python\plugins\manager.py", line 207, in load
plugin._load()
File "..\addons\source-python\packages\source-python\plugins\instance.py", line 74, in _load
self.module = import_module(self.import_name)
File "..\addons\source-python\plugins\stirni_chat_bot\stirni_chat_bot.py", line 22, in <module>
s_cl = ConfigObj(s_basepath + '/stirni_chat_bot.cfg')
File "..\addons\source-python\packages\site-packages\configobj.py", line 1229, in __init__
self._load(infile, configspec)
File "..\addons\source-python\packages\site-packages\configobj.py", line 1318, in _load
raise error
File "<string>", line None

configobj.ConfigObjError: Parsing failed with several errors.
First error at line 49.


2023-01-29 10:58:11 - sp.core.command - MESSAGE [SP] Impossible de charger le plugin 'stirni_chat_bot'.

That error comes from your cfg file.
Here is fixed cfg file for it:

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 ####
#####################
cut-magic
Junior Member
Posts: 19
Joined: Thu Jan 12, 2023 7:16 am

Re: stirni_chat_bot evescriscrip

Postby cut-magic » Sun Jan 29, 2023 1:17 pm

I'm back after some time the python version doesn't speak to me even if the bot is connected but I tested the emulator version modify by you and when I enter the name it seems to react a little but the 2 have a system admin which does not work I must be able to put a Steam3 ID instead of a steam id I am not sure
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: stirni_chat_bot evescriscrip

Postby cssbestrpg » Sun Jan 29, 2023 1:45 pm

I just tested es_emulator version it works fine with steamid3. i haven't yet updated Source.Python plugin version, since i tried to use it gave error when reloaded the plugin when database use.

Edit:

Here is updated version for Source.Python:

Syntax: Select all

import random, pickle, os, path
from configobj import ConfigObj
from events import Event
from players.entity import Player
from commands.say import SayCommand, SayFilter
from commands.client import ClientCommand
from menus import PagedMenu, PagedOption
from messages import SayText2
from colors import GREEN, LIGHT_GREEN
from listeners import OnLevelInit
from filters.players import PlayerIter
from engines.server import engine_server

s_basepath = path.Path(str(__file__)).dirname().replace(os.sep, '/')
s_basename = s_basepath.split('/')[(-1)]
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(',')

@Event('round_start')
def round_start(args):
global s_bot
if s_bot == 0:
for player in PlayerIter('all'):
if player.name == s_bot_specname:
s_bot = 1
if s_bot == 0:
engine_server.create_fake_client(f'{s_bot_specname}')

@OnLevelInit
def map_start(map):
global s_bot
s_bot = 0
s_save_noans()
s_save_responses()

@SayFilter
def say_filter(command, index, teamonly):
if index and command:
name = Player(index).name
args = command.arg_string
text = command[0].lower()
response = 0
if text.lower() in s_bot_shortname or text.lower() in s_bot_fullname:
if response == 0:
for re in s_responses:
if args in re.lower():
SayText2(f'{GREEN}[{LIGHT_GREEN}{s_bot_vname}{GREEN}] \x01{name} {random.choice(s_responses[re])}').send()
response = 1
break

if response == 0:
for hi in s_greeting:
if args in hi.lower():
SayText2(f'{GREEN}[{LIGHT_GREEN}{s_bot_vname}{GREEN}] \x01{random.choice(s_greeting)} {name}').send()
response = 1
break

if response == 0:
for by in s_bye:
if args in by.lower():
SayText2(f'{GREEN}[{LIGHT_GREEN}{s_bot_vname}{GREEN}] \x01{random.choice(s_bye)} {name}').send()
response = 1
break

if response == 0:
for lo in s_love:
if args in lo.lower():
SayText2(f'{GREEN}[{LIGHT_GREEN}{s_bot_vname}{GREEN}] \x01{random.choice(lo)} {name}').send()
response = 1
break

if response == 0:
s_noans.append(text)
s_dontknow(name)

elif text == '!rock':
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 == '!paper':
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 == '!scissors':
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!')

@ClientCommand('!unlearn')
@SayCommand('!unlearn')
def unlearn_command(command, index, teamonly=False):
pass

@ClientCommand('!save')
@SayCommand('!save')
def save_command(command, index, teamonly=False):
steamid = Player(index).steamid
if steamid in s_admins:
s_save_responses()
s_save_noans()
tell(index, 'Saved successfully')

@ClientCommand('!bsay')
@SayCommand('!bsay')
def bsay_command(command, index, teamonly=False):
steamid = Player(index).steamid
args = command.arg_string
if steamid in s_admins:
if args:
SayText2(f'{GREEN}{s_bot_vname} \x01{args}').send()

@ClientCommand('!clear')
@SayCommand('!clear')
def clear_command(command, index, teamonly=False):
global s_responses
steamid = Player(index).steamid
if steamid in s_admins:
del s_noans[:]
s_responses = {}
tell(index, 'Cleared successfully')

@ClientCommand('!dknows')
@SayCommand('!dknows')
def no_knows_command(command, index, teamonly=False):
global s_noans
steamid = Player(index).steamid
if steamid in s_admins:
menu = PagedMenu(title=f'Words {s_bot_shortname} doesnt know!')
for x in s_noans:
menu.append(PagedOption(f'{x}', x))
menu.send(index)

@ClientCommand('!knows')
@SayCommand('!knows')
def knows_command(command, index, teamonly=False):
player = Player(index)
steamid = player.steamid
if steamid in s_admins:
menu = PagedMenu(title=f'Words {s_bot_shortname} does know!')
for x in s_responses:
menu.append(PagedOption(f'{x}', x))
menu.send(index)

@ClientCommand('!learn')
@SayCommand('!learn')
def learn_command(command, index, teamonly=False):
global s_responses
player = Player(index)
args = command.arg_string

steamid = player.steamid
name = player.name
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(index, 'The BOT must have exactly 2 arguments. Use _ if you want to have spaces')
else:
tell(index, 'The BOT must have exactly 2 arguments. Use _ if you want to have spaces')
else:
tell(index, 'The BOT only learns from admins!')

def botmsg(playername, text):
SayText2(f'{GREEN}[{LIGHT_GREEN}CONSOLE Carl{GREEN}] \x01{playername} {text}').send()

def tell_all(text):
SayText2(f'{GREEN}[{LIGHT_GREEN}CONSOLE Carl{GREEN}] \x01{text}').send(index)

def tell(index, text):
SayText2(f'{GREEN}[ChatBot] Stirni{LIGHT_GREEN} {text}').send(index)

def load():
s_get_noans()
s_get_responses()

def unload():
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_get_responses():
global s_responses
if os.path.isfile(s_responses_file):
with open(s_responses_file, 'rb') as s_file:
s_responses = pickle.load(s_file)


def s_save_responses():
with open(s_responses_file, 'wb') as s_file:
pickle.dump(s_responses, s_file)

def s_get_noans():
global s_noans
if os.path.isfile(s_noans_file):
s_file = open(s_noans_file, 'rb')
s_noans = pickle.load(s_file)
s_file.close()

def s_save_noans():
with open(s_noans_file, 'wb') as s_file:
pickle.dump(s_noans, s_file)


Here is cfg for it:

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 = 'CONSOLE Carl'

# 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 ####
#####################
cut-magic
Junior Member
Posts: 19
Joined: Thu Jan 12, 2023 7:16 am

Re: stirni_chat_bot evescriscrip

Postby cut-magic » Sun Jan 29, 2023 8:54 pm

I don't know you manage to make it work correctly on your side but it's not the case for mine even if the plugin is activated the chat does nothing even if I teach him new sentences he does not answer in the chat have you managed to do it spoken with words like hello or hi
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: stirni_chat_bot evescriscrip

Postby cssbestrpg » Sun Jan 29, 2023 8:56 pm

Which version of plugin? Eventscripts emulator or Source.Python?

I tested in Source.Python version if typed carl hello, i got respond Console Carl hello username
cut-magic
Junior Member
Posts: 19
Joined: Thu Jan 12, 2023 7:16 am

Re: stirni_chat_bot evescriscrip

Postby cut-magic » Sun Jan 29, 2023 11:27 pm

last windows version

in the past when evenscrit was still used I talk about the real evescript I don't remember how but the bot plugin had the ability to speak directly in the chat after learning the answers without having to say the name but I don't know why it doesn't is no longer possible but in the code I see that it is possible to replace certain 0s from the 1s I wonder if that's it?
cut-magic
Junior Member
Posts: 19
Joined: Thu Jan 12, 2023 7:16 am

Re: stirni_chat_bot evescriscrip

Postby cut-magic » Mon Jan 30, 2023 2:44 pm

I hadn't told you yet but I think the work you've done to bring this plugin back to life is great and I thank you
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: stirni_chat_bot evescriscrip

Postby cssbestrpg » Mon Jan 30, 2023 8:11 pm

cut-magic wrote:I hadn't told you yet but I think the work you've done to bring this plugin back to life is great and I thank you

Your welcome. You managed got it work like expected?
cut-magic
Junior Member
Posts: 19
Joined: Thu Jan 12, 2023 7:16 am

Re: stirni_chat_bot evescriscrip

Postby cut-magic » Wed Feb 01, 2023 7:14 pm

cssbestrpg wrote:
cut-magic wrote:I hadn't told you yet but I think the work you've done to bring this plugin back to life is great and I thank you

Your welcome. You managed got it work like expected?



unfortunately no, I haven't found how to do it, for example the bot has a paper scissor rock game it works is why you don't need to say the name of the bot before you could do the same thing with recorded sentences the bot understood them without that his name be said but I also notice that he has trouble with certain words when I speak to him I may have forgotten how to speak to him correctly as it has been several years since I had not used the bot but it is nice to ask I think I'll look if alternatives to this bot exist but on sourcemod
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: stirni_chat_bot evescriscrip

Postby cssbestrpg » Wed Feb 01, 2023 7:44 pm

I can update the code that bot respond without having calling his name.

Here updated code for it:

Syntax: Select all

import random, pickle, os, path
from configobj import ConfigObj
from events import Event
from players.entity import Player
from commands.say import SayCommand, SayFilter
from commands.client import ClientCommand
from menus import PagedMenu, PagedOption
from messages import SayText2
from colors import GREEN, LIGHT_GREEN
from listeners import OnLevelInit
from filters.players import PlayerIter
from engines.server import engine_server

s_basepath = path.Path(str(__file__)).dirname().replace(os.sep, '/')
s_basename = s_basepath.split('/')[(-1)]
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(',')

@Event('round_start')
def round_start(args):
global s_bot
if s_bot == 0:
for player in PlayerIter('all'):
if player.name == s_bot_specname:
s_bot = 1
if s_bot == 0:
engine_server.create_fake_client(f'{s_bot_specname}')

@OnLevelInit
def map_start(map):
global s_bot
s_bot = 0
s_save_noans()
s_save_responses()

@SayFilter
def say_filter(command, index, teamonly):
if index and command:
name = Player(index).name
text = command[0].lower()
response = 0
for re in s_responses:
if text in re.lower():
SayText2(f'{GREEN}[{LIGHT_GREEN}{s_bot_vname}{GREEN}] \x01{name} {random.choice(s_responses[re])}').send()
response = 1
break

for hi in s_greeting:
if text in hi.lower():
SayText2(f'{GREEN}[{LIGHT_GREEN}{s_bot_vname}{GREEN}] \x01{random.choice(s_greeting)} {name}').send()
response = 1
break


for by in s_bye:
if text in by.lower():
SayText2(f'{GREEN}[{LIGHT_GREEN}{s_bot_vname}{GREEN}] \x01{random.choice(s_bye)} {name}').send()
response = 1
break

for lo in s_love:
if text in lo.lower():
SayText2(f'{GREEN}[{LIGHT_GREEN}{s_bot_vname}{GREEN}] \x01{random.choice(lo)} {name}').send()
response = 1
break

if response == 0:
s_noans.append(text)
s_dontknow(name)

elif text == '!rock':
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 == '!paper':
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 == '!scissors':
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!')

@ClientCommand('!unlearn')
@SayCommand('!unlearn')
def unlearn_command(command, index, teamonly=False):
pass

@ClientCommand('!save')
@SayCommand('!save')
def save_command(command, index, teamonly=False):
steamid = Player(index).steamid
if steamid in s_admins:
s_save_responses()
s_save_noans()
tell(index, 'Saved successfully')
return False

@ClientCommand('!bsay')
@SayCommand('!bsay')
def bsay_command(command, index, teamonly=False):
steamid = Player(index).steamid
args = command.arg_string
if steamid in s_admins:
if args:
SayText2(f'{GREEN}{s_bot_vname} \x01{args}').send()
return False

@ClientCommand('!clear')
@SayCommand('!clear')
def clear_command(command, index, teamonly=False):
global s_responses
steamid = Player(index).steamid
if steamid in s_admins:
del s_noans[:]
s_responses = {}
tell(index, 'Cleared successfully')
return False

@ClientCommand('!dknows')
@SayCommand('!dknows')
def no_knows_command(command, index, teamonly=False):
global s_noans
steamid = Player(index).steamid
if steamid in s_admins:
menu = PagedMenu(title=f'Words {s_bot_shortname} doesnt know!')
for x in s_noans:
menu.append(PagedOption(f'{x}', x))
menu.send(index)
return False

@ClientCommand('!knows')
@SayCommand('!knows')
def knows_command(command, index, teamonly=False):
player = Player(index)
steamid = player.steamid
if steamid in s_admins:
menu = PagedMenu(title=f'Words {s_bot_shortname} does know!')
for x in s_responses:
menu.append(PagedOption(f'{x}', x))
menu.send(index)
return False

@ClientCommand('!learn')
@SayCommand('!learn')
def learn_command(command, index, teamonly=False):
global s_responses
player = Player(index)
args = command.arg_string

steamid = player.steamid
name = player.name
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(index, 'The BOT must have exactly 2 arguments. Use _ if you want to have spaces')
else:
tell(index, 'The BOT must have exactly 2 arguments. Use _ if you want to have spaces')
else:
tell(index, 'The BOT only learns from admins!')

def botmsg(playername, text):
SayText2(f'{GREEN}[{LIGHT_GREEN}CONSOLE Carl{GREEN}] \x01{playername} {text}').send()

def tell_all(text):
SayText2(f'{GREEN}[{LIGHT_GREEN}CONSOLE Carl{GREEN}] \x01{text}').send(index)

def tell(index, text):
SayText2(f'{GREEN}[ChatBot Stirni] {LIGHT_GREEN}{text}').send(index)

def load():
s_get_noans()
s_get_responses()

def unload():
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_get_responses():
global s_responses
if os.path.isfile(s_responses_file):
with open(s_responses_file, 'rb') as s_file:
s_responses = pickle.load(s_file)


def s_save_responses():
with open(s_responses_file, 'wb') as s_file:
pickle.dump(s_responses, s_file)

def s_get_noans():
global s_noans
if os.path.isfile(s_noans_file):
s_file = open(s_noans_file, 'rb')
s_noans = pickle.load(s_file)
s_file.close()

def s_save_noans():
with open(s_noans_file, 'wb') as s_file:
pickle.dump(s_noans, s_file)


Now it should work say hi and it respons

Edit:
Fixed bot answer non teached words
Last edited by cssbestrpg on Sat Feb 04, 2023 1:40 pm, edited 2 times in total.
cut-magic
Junior Member
Posts: 19
Joined: Thu Jan 12, 2023 7:16 am

Re: stirni_chat_bot evescriscrip

Postby cut-magic » Thu Feb 02, 2023 7:02 pm

what you have done is almost perfect I have just tested but it would be possible that the bot speaks only once with each message and also he answered me when I wrote test however I had not taught him these words
cut-magic
Junior Member
Posts: 19
Joined: Thu Jan 12, 2023 7:16 am

Re: stirni_chat_bot evescriscrip

Postby cut-magic » Thu Feb 02, 2023 7:05 pm

I just saw that the bot connect several times now I have more than 15 bot in spectator
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: stirni_chat_bot evescriscrip

Postby cssbestrpg » Thu Feb 02, 2023 7:24 pm

cut-magic wrote:I just saw that the bot connect several times now I have more than 15 bot in spectator

Just tested in css, it works fine for me, only one bot joined.
Here is fixed version of the code.
cut-magic
Junior Member
Posts: 19
Joined: Thu Jan 12, 2023 7:16 am

Re: stirni_chat_bot evescriscrip

Postby cut-magic » Thu Feb 02, 2023 7:32 pm

cssbestrpg wrote:
cut-magic wrote:I just saw that the bot connect several times now I have more than 15 bot in spectator

Just tested in css, it works fine for me, only one bot joined.
Here is fixed version of the code.



when the spectator bot starts to join it's after 4 to 5 minutes at the beginning I just have the normal chat bot but my server already has 2 bots playing to reproduce the bug you should maybe put 2 play and wait 4 minutes

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 9 guests