i can weakly read french (im learning it) but
i am unable to write as for now, so maybe let me ask
this question in english but you may answer
in french
im experienced in c but im total noob in python,
maybe you can give me some hints
i write a irc bot (nicknamed 'minion') in python,
i want to make such thing, if user will
send a line like
<fir> minion invite emily = hello emilly minion welcomes you
this line is stored in text file fir.txt as a line
invite emily = hello emilly minion welcomes you
then if i will send a line
<fir> minion invite emily
then minion will send
<minion> hello emilly minion welcomes you
obvoiusly linnes should be added and if same 'key' found
(in that case key is "invite emily") then it should be
replaced
i also would want to mke it with some sense not to make
bery much disk reads maybe
i know python like 3 days and dont see how to do it yet
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
john Stone
W dniu niedziela, 12 kwietnia 2020 15:43:22 UTC+2 użytkownik john Ston e napisał:
salute, i can weakly read french (im learning it) but i am unable to write as for now, so maybe let me ask this question in english but you may answer in french im experienced in c but im total noob in python, maybe you can give me some hints i write a irc bot (nicknamed 'minion') in python, i want to make such thing, if user will send a line like <fir> minion invite emily = hello emilly minion welcomes you this line is stored in text file fir.txt as a line invite emily = hello emilly minion welcomes you then if i will send a line <fir> minion invite emily then minion will send <minion> hello emilly minion welcomes you obvoiusly linnes should be added and if same 'key' found (in that case key is "invite emily") then it should be replaced i also would want to mke it with some sense not to make bery much disk reads maybe i know python like 3 days and dont see how to do it yet can someone help, tnx
ok i found it p = ircmsg.find(channel) r = ircmsg.find('===') if p!=-1 and r!=-1: key = ircmsg[p+len(channel)+1:r] value = ircmsg[r+1+1+1:] say("przyjalem") bot_memory[key]=value save_bot_memory() p = ircmsg.find(channel) if p!=-1: key = ircmsg[p+len(channel)+1:] if key in bot_memory: say(bot_memory[key]) where import json bot_memory = {'a': 'a', 'b': 'b', 'c': 'c'} f = open("bot_memory.json", 'r') bot_memory = json.load(f) f.close() def save_bot_memory(): j = json.dumps(bot_memory) f = open("bot_memory.json","w") f.write(j) f.close() return i hope this is ok
W dniu niedziela, 12 kwietnia 2020 15:43:22 UTC+2 użytkownik john Ston e napisał:
salute,
i can weakly read french (im learning it) but
i am unable to write as for now, so maybe let me ask
this question in english but you may answer
in french
im experienced in c but im total noob in python,
maybe you can give me some hints
i write a irc bot (nicknamed 'minion') in python,
i want to make such thing, if user will
send a line like
<fir> minion invite emily = hello emilly minion welcomes you
this line is stored in text file fir.txt as a line
invite emily = hello emilly minion welcomes you
then if i will send a line
<fir> minion invite emily
then minion will send
<minion> hello emilly minion welcomes you
obvoiusly linnes should be added and if same 'key' found
(in that case key is "invite emily") then it should be
replaced
i also would want to mke it with some sense not to make
bery much disk reads maybe
i know python like 3 days and dont see how to do it yet
can someone help, tnx
ok i found it
p = ircmsg.find(channel)
r = ircmsg.find('===')
if p!=-1 and r!=-1:
key = ircmsg[p+len(channel)+1:r]
value = ircmsg[r+1+1+1:]
say("przyjalem")
bot_memory[key]=value
save_bot_memory()
p = ircmsg.find(channel)
if p!=-1:
key = ircmsg[p+len(channel)+1:]
if key in bot_memory:
say(bot_memory[key])
where
import json
bot_memory = {'a': 'a',
'b': 'b',
'c': 'c'}
f = open("bot_memory.json", 'r')
bot_memory = json.load(f)
f.close()
W dniu niedziela, 12 kwietnia 2020 15:43:22 UTC+2 użytkownik john Ston e napisał:
salute, i can weakly read french (im learning it) but i am unable to write as for now, so maybe let me ask this question in english but you may answer in french im experienced in c but im total noob in python, maybe you can give me some hints i write a irc bot (nicknamed 'minion') in python, i want to make such thing, if user will send a line like <fir> minion invite emily = hello emilly minion welcomes you this line is stored in text file fir.txt as a line invite emily = hello emilly minion welcomes you then if i will send a line <fir> minion invite emily then minion will send <minion> hello emilly minion welcomes you obvoiusly linnes should be added and if same 'key' found (in that case key is "invite emily") then it should be replaced i also would want to mke it with some sense not to make bery much disk reads maybe i know python like 3 days and dont see how to do it yet can someone help, tnx
ok i found it p = ircmsg.find(channel) r = ircmsg.find('===') if p!=-1 and r!=-1: key = ircmsg[p+len(channel)+1:r] value = ircmsg[r+1+1+1:] say("przyjalem") bot_memory[key]=value save_bot_memory() p = ircmsg.find(channel) if p!=-1: key = ircmsg[p+len(channel)+1:] if key in bot_memory: say(bot_memory[key]) where import json bot_memory = {'a': 'a', 'b': 'b', 'c': 'c'} f = open("bot_memory.json", 'r') bot_memory = json.load(f) f.close() def save_bot_memory(): j = json.dumps(bot_memory) f = open("bot_memory.json","w") f.write(j) f.close() return i hope this is ok