This repository was archived by the owner on Mar 14, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsnakes.py
More file actions
155 lines (125 loc) · 5.46 KB
/
Copy pathsnakes.py
File metadata and controls
155 lines (125 loc) · 5.46 KB
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
# coding=utf-8
import logging
import random
from typing import Any, Dict
from discord import Embed
import wikipedia
from discord.ext.commands import AutoShardedBot, Context, command
log = logging.getLogger(__name__)
SNAKE_LIST = ['cobra', 'python', 'anaconda', 'viper', 'mamba', 'taipan', 'rattle', 'garter', 'cylindrophis',
'colubridae']
class Snakes:
"""
Snake-related commands
"""
def __init__(self, bot: AutoShardedBot):
self.bot = bot
async def get_snek(self, name: str = None) -> Dict[str, Any]:
"""
Go online and fetch information about a snake
The information includes the name of the snake, a picture of the snake, and various other pieces of info.
What information you get for the snake is up to you. Be creative!
If "python" is given as the snake name, you should return information about the programming language,
but with
all the information you'd provide for a real snake. Try to have some fun with this!
:param name: Optional, the name of the snake to get information for - omit for a random snake
:return: A dict containing information on a snake
"""
if name is None:
name = random.choice(SNAKE_LIST)
elif name.lower() == "python":
name = "Python(Programming Language)"
try:
text = wikipedia.summary(name, sentences=2)
except Exception as e:
text = wikipedia.summary(e.options[0], sentences=2)
return (name, text)
@command(name="get")
async def get(self, ctx: Context, name: str = None):
name, text = await self.get_snek(name)
for_image = ''
if name == "Python(Programming Language)":
for_image = 'https://raw.githubusercontent.com/discord-python/branding/master/logos/logo_full.png'
embed = Embed(title="Programming !!", color=0x00ff00)
embed.add_field(name=name, value=text)
embed.set_image(url=for_image)
await ctx.send(embed=embed)
else:
webpage = wikipedia.WikipediaPage(name)
for_image = webpage.images[0]
embed = Embed(title="Snake !!", color=0x00ff00)
embed.add_field(name=name, value=text)
embed.set_image(url=for_image)
await ctx.send(embed=embed)
# Any additional commands can be placed here. Be creative, but keep it to a reasonable amount!
@command(name="snakerandom")
async def snake_random(self, ctx: Context, name: str = None):
randsnake = random.choice(SNAKE_LIST)
print(randsnake)
embed = Embed(
title="Snake Random !",
description="lets see what snake you got !",
color=0x00ff00,
)
embed.add_field(name="Result", value="You got yourself a " + randsnake, inline=False)
embed.add_field(name="Expectation", value=f"@{ctx.author} expected {name}", inline=False)
if randsnake == "python":
return await ctx.send("You're a lucky dude ! ", embed=embed)
elif randsnake == "cobra":
return await ctx.send("Good old cobra !", embed=embed)
elif randsnake.startswith("blac"):
return await ctx.send("Shiny liitle fella !", embed=embed)
@command(name="randname") # this name generator randomply slics strings and joins them
async def Random_name(self, ctx: Context, name: str = None):
snk = random.choice(SNAKE_LIST)
snLen = len(snk)
p = len(name)
result = ""
front_back = 1
if front_back == 1: # so the users name is substring from the front and snake random substring from back
ran = random.randint(1, p - 2)
ranSnk = random.randint(1, snLen - 1)
result = name[:ran] + snk[ranSnk:]
embed = Embed(
title="Random Name",
description="You're that is generated is " + result,
color=0x00ff00
)
embed.add_field(name="Snake", value="Your name was merged with the snake " + snk)
return await ctx.send(embed=embed)
@command(name="namegen") # this name generator looks at vowels
async def name_generator(self, ctx: Context, name: str = None):
snk = random.choice(SNAKE_LIST)
s = name
str1 = ""
str2 = ""
for i in s:
str1 = i + str1
index2 = 0
index1 = 0
for index, char in enumerate(str1):
if char in 'aeiou':
index1 = index
break
name_index = len(s) - index1
name_sub_string = s[:name_index - 1]
snake = snk
for i in snake:
str2 = i + str2
for index, char in enumerate(str2):
if char in 'aeiou':
index2 = index
break
sub_string_index = len(snake) - index2
snake_sub_string = snake[1:sub_string_index]
result = name_sub_string + snake_sub_string
embed = Embed(
title="NAME GENERATOR",
description="You're that is generated is " + result,
color=0x00ff00
)
embed.add_field(name="Snake", value="Your name was merged with the snake " + snake)
return await ctx.send(embed=embed)
def setup(bot):
bot.add_cog(Snakes(bot))
log.info("Cog loaded: Snakes")