forked from AlexisHuvier/HugoBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhugoland.py
185 lines (176 loc) · 9.75 KB
/
hugoland.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import discord, asyncio, varHugoland, urllib.request, socket
from bs4 import BeautifulSoup
class HugoBot(discord.Client):
def __init__(self):
super().__init__()
self.version = "1.4.0"
async def on_ready(self):
print(self.user.name)
print(self.user.id)
async def on_message(self,message):
if message.author.id == "307984283774222348":
msg = message.content.lower()
if "ok" in msg or "\U0001F197" in msg or ("\U0001F1F4" in msg and "\U0001F1F0" in msg):
await self.delete_message(message)
if message.content.startswith("!etat"):
hote = "91.134.149.66"
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 25565
try:
connection.connect((hote, port))
connection.close()
await self.send_message(message.channel, "Le serveur RP est ouvert")
except ConnectionRefusedError:
await self.send_message(message.channel, "Le serveur RP est fermé. <@226748223006441472>, merci d'ouvrir le serveur")
connection2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 20000
try:
connection2.connect((hote, port))
connection2.close()
await self.send_message(message.channel, "Le serveur détente est ouvert")
except ConnectionRefusedError:
await self.send_message(message.channel, "Le serveur détente est fermé. <@226748223006441472>, merci d'ouvrir le serveur")
if message.content.startswith("!wiki"):
if len(message.content) == 5 or len(message.content) == 6:
await self.send_message(message.channel,"ERREUR : Utilise !wiki <recherche>")
else:
msg = message.content.split(" ")
keyWords=""
for i in range(1, len(msg)):
if i == len(msg)-1:
keyWords += msg[i]
else:
keyWorlds += msg[i] + " "
adresse = "http://fr.hugoland-minecraft.wikia.com/wiki/Spécial:Recherche?query="+keyWords
await self.send_message(message.channel,adresse)
if message.content.startswith("!ping"):
await self.send_message(message.channel, "Pong ! Je suis toujours là")
if message.content.startswith("!help"):
aide = discord.Embed(title="HugoBot - Help System V" + self.version, description="Système d'assistance d'HugoBot", colour = 0x2ecc71)
aide.set_footer(text="HugoBot - Help System V" + self.version,icon_url="https://cdn4.iconfinder.com/data/icons/meBaze-Freebies/512/info.png")
aide.add_field(name = "- !help", value = "Commande actuelle", inline = False)
aide.add_field(name = "- !info", value = "Informations sur moi", inline = False)
aide.add_field(name = "- !staff", value = "Le Staff de la communauté", inline = False)
aide.add_field(name = "- !ping", value = "Pour savoir si je suis là", inline = False)
aide.add_field(name = "- !haddock", value = "Génère aléatoirement un juron façon Cpt. Haddock", inline = False)
aide.add_field(name = "- !wiki <article>", value = "Poste le lien d'un article du wiki", inline = False)
aide.add_field(name = "- !new <article>", value = "Poste la création d'un nouvel article du wiki dans le salon #actu-wiki", inline = False)
aide.add_field(name = "- !màj <article>", value = "Poste la dernière mise à jour d'un article du wiki dans le salon #actu-wiki", inline = False)
aide.add_field(name = "- !cours <id bloc/item>", value = "Poste les prix actuels du bloc/item ayant l'id donné", inline = False)
aide.add_field(name = "- !etat", value="Vérifie l'état des serveurs et mentionne LavaPower pour les relancer", inline = False)
await self.send_message(message.channel,embed=aide)
if message.content.startswith("!info"):
info = discord.Embed(title="HugoBot", description="Bot d'Hugoland", colour = 0x3498db)
info.set_footer(text="HugoBot",icon_url="https://cdn4.iconfinder.com/data/icons/meBaze-Freebies/512/info.png")
info.add_field(name = "Codé par",value = "LavaPower et Spyromain")
info.add_field(name = "Version",value=self.version)
await self.send_message(message.channel,embed=info)
if message.content.startswith("!staff"):
staff = discord.Embed(title="Staff", description="Staff d'Hugoland", colour = 0x3498db)
staff.set_footer(text="Staff",icon_url="https://cdn4.iconfinder.com/data/icons/meBaze-Freebies/512/info.png")
staff.add_field(name = "Administrateur",value="Hugo7", inline = False)
staff.add_field(name = "Modérateur",value="LavaPower", inline = False)
staff.add_field(name = "Développeur",value="Spyromain", inline = False)
await self.send_message(message.channel,embed=staff)
if message.content.startswith("!haddock"):
with urllib.request.urlopen("http://data.hugoland.fr/haddock.php?method=clair") as response:
haddock = response.read().decode('utf8')
await self.send_message(message.channel, haddock)
if message.content.startswith("!new"):
if message.content == "!new":
await self.send_message(message.channel, "Usage : !new <article>")
elif len(message.content) > 4 and message.content[4] != " ":
await self.send_message(message.channel, "Commande inconnue. Peut-être souhaitiez-vous utiliser la commande !new <article> ?")
else:
arg = message.content[5:]
if not arg:
await self.send_message(message.channel, "Usage : !new <article>")
else:
url = "http://fr.hugoland-minecraft.wikia.com/wiki/" + urllib.parse.quote(arg)
history = url + "?action=history"
with urllib.request.urlopen(history) as response:
try:
data = response.read().decode("utf8")
soup = BeautifulSoup(data, "html.parser")
author = soup.find_all("a", class_="mw-userlink")[-1].text
msg = "**N** <" + url + ">\n" \
+ "Par " + author
await self.send_message(self.get_channel("356129617779621890"), msg)
except:
await self.send_message(message.channel, "Article introuvable")
if message.content.startswith("!màj"):
if message.content == "!màj":
await self.send_message(message.channel, "Usage : !màj <article>")
elif len(message.content) > 4 and message.content[4] != " ":
await self.send_message(message.channel, "Commande inconnue. Peut-être souhaitiez-vous utiliser la commande !màj <article> ?")
else:
arg = message.content[5:]
if not arg:
await self.send_message(message.channel, "Usage : !màj <article>")
else:
url = "http://fr.hugoland-minecraft.wikia.com/wiki/" + urllib.parse.quote(arg)
history = url + "?action=history"
with urllib.request.urlopen(history) as response:
try:
data = response.read().decode("utf8")
soup = BeautifulSoup(data, "html.parser")
author = soup.find("a", class_="mw-userlink").text
comment = soup.find("span", class_="comment").text
msg = "**MÀJ** <" + url + ">\n" \
+ "Par " + author + " : " + comment
await self.send_message(self.get_channel("356129617779621890"), msg)
except:
await self.send_message(message.channel, "Article introuvable")
if message.content.startswith("!cours"):
if message.content == "!cours":
await self.send_message(message.channel, "Usage : !cours <id bloc/item>")
elif len(message.content) > 6 and message.content[6] != " ":
await self.send_message(message.channel, "Commande inconnue. Peut-être souhaitiez-vous utiliser la commande !cours <id bloc/item> ?")
else:
arg = message.content[7:]
if not arg:
await self.send_message(message.channel, "Usage : !cours <id bloc/item>")
else:
url = "http://data.hugoland.fr/mc/cours.php?id=" + urllib.parse.quote(arg)
with urllib.request.urlopen(url) as response:
data = response.read().decode("utf8")
soup = BeautifulSoup(data, "html.parser")
msg = ""
if arg == "172":
msg += "**Attention :** les blocs d'argile durcie colorée se " \
+ "calculent comme ceci : prix du bloc d'argile durcie auquel on " \
+ "ajoute une valeur de quelques pièces par demi-stack par " \
+ "niveau de rareté\n"
prix1 = soup.find("span", id="prix1")
if prix1:
prix1 = prix1.text
if arg == "122":
prix6 = soup.find("span", id="prix6").text
prix12 = soup.find("span", id="prix12").text
msg += "**~~Easteregg~~ DRAGONEGG**\n" \
+ "**== ID " + arg + " ==**\n" \
+ "Prix à l'unité : " + prix1 + "p\n" \
+ "Prix à la demi-douzaine : " + prix6 + "p\n" \
+ "Prix à la douzaine : " + prix12 + "p"
else:
prix8 = soup.find("span", id="prix8").text
prix16 = soup.find("span", id="prix16").text
prix64 = soup.find("span", id="prix64").text
msg += "**== ID " + arg + " ==**\n" \
+ "Prix à l'unité : " + prix1 + "p\n" \
+ "Prix pour 8 : " + prix8 + "p\n" \
+ "Prix pour 16 : " + prix16 + "p\n" \
+ "Prix pour 64 : " + prix64 + "p"
else:
msg += "Aucun coefficient n'est attribué à cet id"
await self.send_message(message.channel, msg)
async def on_message_edit(self, before, after):
if after.author.id == "307984283774222348":
msg = after.content.lower()
if "ok" in msg or "\U0001F197" in msg or ("\U0001F1F4" in msg and "\U0001F1F0" in msg):
await self.delete_message(after)
async def on_reaction_add(self, reaction, user):
if user.id == "307984283774222348" and all(letter in [x.emoji for x in reaction.message.reactions] for letter in ("\U0001F1F4", "\U0001F1F0")):
await self.remove_reaction(reaction.message, reaction.emoji, user)
client = HugoBot()
client.run(varHugoland.getVar())