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
|
from discord.ext import commands
from discord.ext import tasks
import discord
import requests
import json
import asyncio
from datetime import timedelta
from google.cloud import translate_v2 as translate
translate_client = translate.Client()
import random
async def translateMsg(text, target="en"):
# Text can also be a sequence of strings, in which case this method
# will return a sequence of results for each text.
result = translate_client.translate(
text, target_language=target)
print(u'Text: {}'.format(result['input']))
print(u'Translation: {}'.format(result['translatedText']))
print(u'Detected source language: {}'.format(
result['detectedSourceLanguage']))
return result;
class Utils(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(description="Pong!", help="Tells the ping of the bot to the discord servers", brief="Tells the ping")
async def ping(self, ctx):
await ctx.send(f'Pong! {round(self.bot.latency*1000)}ms')
@commands.command(help="Translate text in english (using google translate)", brief="Translate to english")
async def translate(self, ctx, *, message):
response = await translateMsg(message)
embed=discord.Embed(title="Translation",description=f"{ctx.message.author.mention} says:", timestamp=ctx.message.created_at, color=0x4d9aff)
embed.add_field(name=f"[{response['detectedSourceLanguage']}] Source:" , value=response['input'], inline=False)
embed.add_field(name="Translation", value=response['translatedText'], inline=True)
await ctx.send(embed=embed)
@commands.command()
async def trans(self, ctx, lan, *, message):
response = await translateMsg(message, lan)
embed=discord.Embed(title="Translation",description=f"{ctx.message.author.mention} says:", timestamp=ctx.message.created_at, color=0x4d9aff)
embed.add_field(name=f"[{response['detectedSourceLanguage']}] Source:" , value=response['input'], inline=False)
embed.add_field(name="Translation", value=response['translatedText'], inline=True)
await ctx.send(embed=embed)
@commands.cooldown(1, 25, commands.BucketType.guild)
@commands.command()
async def findseed(self, ctx):
if ctx.message.channel.id != 684787316489060422:
ctx.message.delete()
return
totalEyes = 0
for i in range(12):
randomness = random.randint(1,10)
if randomness == 1:
totalEyes += randomness
else:
continue
await ctx.send(f"{ctx.message.author.display_name} -> your seed is a {totalEyes} eye")
@findseed.error
async def findseed_handler(self,ctx,error):
if isinstance(error, commands.CommandOnCooldown):
if ctx.message.channel.id != 684787316489060422:
ctx.message.delete()
return
#await ctx.send(f"{ctx.message.author.display_name}, you have to wait {round(error.retry_after, 7)} seconds before using this again.")
@commands.Cog.listener()
async def on_message(self, message):
if message.channel.id != 589110766578434078:
return
if message.author.bot:
return
badWords = ["fair", "f a i r", "ⓕⓐⓘⓡ", "ⓕ ⓐ ⓘ ⓡ"]
count = 0
for word in badWords:
if word in message.content.lower():
count += 1;
fair = 'Fair '*count
await message.channel.send(fair)
def setup(bot):
bot.add_cog(Utils(bot))
|