Race value is an important factor in determining stats in Pokemon. In fact, when you play Pokemon, you may not be able to play a decent game unless you know the race value. At present, if you don't know the race value of Pokemon, you have to do a Google search every time, which I found to be troublesome. So I started to think that it would be convenient to have a chat bot that interactively tells me the race value.
There are three main purposes.
--Reduced search effort --Activation of Discord server -Get parts and knowledge that can be used for future development
Specifically, the parts and knowledge that can be used for development include "Pokemon race value database" and "Common Pokemon name mistakes". (I want to correct it to the correct Pokemon name by knowing how to make a mistake in a common Pokemon name)
[Pokemon name] pictorial book
When you chat with, it will tell you the race value of Pokemon.
For the time being, I installed it only on the discord server I run.
Introduction of Discord server "Gatserver" for Pokemon Gachi
About 200 people participated, including several people who have experienced first place in the season.
[github](https://github.com/ryoYAMAZAKI11/Pokemonbot )
【local】 MacOS Catalina Ver. 10.15.4 Python Ver. 3.7.7 【server】 I made the bot resident on xserver by following the procedure on the following site. https://ogapsan.com/archives/1077
I looked it up on a Discord Bot and found Python to be fun. I saved the Pokemon race value data in a json file as a database in advance, and made it "take out the race value data and make it react to Discord Bot" in Python.
Created with reference to National Encyclopedia of Pokemon Thorough Strategy.
Part of the database
{
...
"Charmander":{"No":"4","Pokemon name":"Charmander","HP":"39","attack":"52","defense":"43","Special attack":"60","Special defense":"50","Agility":"65","total":"309"},
"Lizard":{"No":"5","Pokemon name":"Lizard","HP":"58","attack":"64","defense":"58","Special attack":"80","Special defense":"65","Agility":"80","total":"405"},
"Charizard":{"No":"6","Pokemon name":"Charizard","HP":"78","attack":"84","defense":"78","Special attack":"109","Special defense":"85","Agility":"100","total":"534"},
...
}
https://qiita.com/1ntegrale9/items/9d570ef8175cf178468f I installed discord.py from the acquisition of the bot token with reference to.
The source code is below
main.py
import sys
import discord
import json
from collections import OrderedDict
import pprint
import re
import bot_token
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as', file=sys.stderr)
print(client.user.name, file=sys.stderr)
print(client.user.id, file=sys.stderr)
print('------', file=sys.stderr)
@client.event
async def on_message(message):
#I don't want to react if the sender is a bot
if message.author.bot:
return
#Find out if it starts with "picture book"
if message.content == 'Zakoyama's illustrated book':
message_send = "The creator of this bot, Lotto!" + "\n" + "Lotto to contact us on twitter for any problems!"+ "\n" + "https://twitter.com/zakoyama_com"
elif re.match('.+Picture book$', message.content):
json_open = open('pokedex_zen.json', 'r')
json_load = json.load(json_open)
#Get the Pokemon name from the message (remove the "picture book" part)
m = message.content[0:len(message.content)-3]
#Send a message to the channel to which the message was sent
if m in json_load:
message_send = "```"
for key, value in json_load[m].items():
if key == 'No':
message_send = message_send + '%s.%s'%(key, value) + ' '
elif key =='Pokemon name':
message_send = message_send +'% s'% (value) + "\ n" +'HP Attack Defense Special Attack Special Defense Quick Total \ n'
elif key == 'HP' :
message_send = message_send + '%3d'%(int(value))
else:
message_send = message_send + '%4d'%(int(value))
message_send = message_send + "```"
print('0 ' + m)#To log
else:
message_send = "Lotto where no Pokemon can be found!"
print('1 ' + m)#To log
await message.channel.send(message_send)
client.run(bot_token.TOKEN)
bot_token.py
TOKEN = "Tokens obtained here"
Most of the users are Japanese, and it is said that they are inputting from a smartphone, so commands like `! P``` that are common in Discord bots are not good? I thought. Therefore, the bot responds with the
[Pokemon name] picture book
`` which is easy to input even from a smartphone.
main.Excerpt from py
elif re.match('.+Picture book$', message.content):
In this way, it is extracted using the regular expression module `` `re```.
main.Excerpt from py
#Get the Pokemon name from the message (remove the "picture book" part)
m = message.content[0:len(message.content)-3]
The Pokemon name was stored in the variable `` `m``` by removing the three-letter" picture book "part from the end.
In Discord, the character width of alphabets and spaces differs depending on the type. Therefore, just arranging them will cause a large deviation like this. So I used the Discord code block. "```If you enclose it in ", it becomes a code block. The size of the alphabet and half-width space is unified, and the Japanese character size is also smaller, making it easier to see. However, the size of full-width Japanese and alphabets and half-width spaces is 2:Since it is not 1, it seems that it will shift a little when trying to translate it into Japanese. It is implemented as follows in the source code.
main.Excerpt from py
#Send a message to the channel to which the message was sent
if m in json_load:
message_send = "```"#Start the code block here
for key, value in json_load[m].items():
if key == 'No':
message_send = message_send + '%s.%s'%(key, value) + ' '
elif key == 'Pokemon name':
message_send = message_send + '%s'%(value) + " \n" + 'HP Attack Defense Special Attack Special Defense Quick Total\n'
elif key == 'HP' :
message_send = message_send + '%3d'%(int(value))
else:
message_send = message_send + '%4d'%(int(value))
message_send = message_send + "` `` "# Close the code block here
###Point 3: Log is standard output If it is true, I wanted to record a log and make it like "Pokemon ranking that is searched a lot", but I do not feel like I can make it immediately, and the purpose of logging is "I want to know how to make a mistake in a common Pokemon name" Therefore, I decided to make the standard output log and record it. It is spit out by the print function as follows.
main.Excerpt from py
print ('0' + m) # To log
...
print ('1' + m) # To log
If a Pokemon is found0
, If not found1
You can check "common mistakes in Pokemon names". (If you perform text processing, you can also find out which Pokemon are often searched)
Part of the log
0 Heat Rotom
0 Gyarados
0 Cinccino
0 Froslass
1 Alola Ninetales
0 Ninetales
0 Togekiss
When executing on the server to take this log, execute with the following command.
nohup python3 main.py 1>> out.log 2> /dev/null &
with thisout.log
Is logged.
#Achievement of purpose
I introduced this bot for about 2 months. Check the achievement level for each of the three objectives.
-Reduced search effort -Discord server activation -Acquire parts and knowledge that can be used for future development
###Reduced search effort It's pretty easy. You don't have to do a google search, so it's easy. However, since the race value alone is not enough as information and I want to know the technique and characteristics, I may end up doing a google search. This is a future issue.
###Discord server activation At the beginning of the introduction of the bot, there were about 20 participants, but the number has exceeded 200. It has become quite active. It is thought that one of the reasons is that the tweets in the process of being created received a lot of RT. Extended tweets
###Acquire parts and knowledge that can be used for future development I was able to create a list of Pokemon race values.
Regarding the log, when I checked it and found no Pokemon, it was filled with 80% off-color humor and was useless. Probably a triggerPicture book of
Because〜
It seems that there are people who are playing with obscene words in the part of.
#Summary It was created in one week and adjusted while being introduced for about two months. I've made something with a decent function, but honestly, it's not working very well (about once a day). I will continue to improve it without fail.
What impressed me was that when the tweet was RT, many people said that they wanted to use it, but few actually used it. I keenly realized that the needs that people say and the true needs that are actually needed may be different.
Recommended Posts