diff --git a/cogs/copypasta/copypasta.csv b/cogs/copypasta/copypasta.csv new file mode 100644 index 0000000..d1376f4 --- /dev/null +++ b/cogs/copypasta/copypasta.csv @@ -0,0 +1,3 @@ +id,name,copypasta +0,"emacs","Using eMacs actually has nothing to do with productivity. In fact, I’m not even trying to optimize it. I simply think it’s a good tool for keeping me organized. Why do some people live their life in a constant state of disarray, rushing from place to place, never knowing what they need to do besides their immediate task, constantly worrying about their deadlines when they can instead live in peace? Emacs is one of the many tools I use to organize my life, to take my mind off the things that don’t matter and let a machine remember for me. I live knowing that, at the end of the day, everything will be ok. There’s nothing urgent that needs to be on my mind because I have written it down for thought later. Emacs is not about productivity. Emacs is about organization, a system I can tune to my needs, so that I can live a stress-free, fulfilling life. - Richard" +1,"test","testtttttttttt" diff --git a/cogs/copypasta/copypasta.py b/cogs/copypasta/copypasta.py new file mode 100644 index 0000000..54a87bb --- /dev/null +++ b/cogs/copypasta/copypasta.py @@ -0,0 +1,56 @@ +import interactions +from interactions import Extension, SlashContext + +from lib.util import command, subcommand + +import csv +import os +import random + +filepath = os.path.dirname(os.path.abspath(__file__)) + "/copypasta.csv" + +class copypasta(Extension): + + def __init__(self,bot): + self.id_lst = [] + self.name_lst = [] + self.pasta_lst = [] + with open(filepath) as csvfile: + reader = csv.reader(csvfile) + row = next(reader) + for row in reader: + self.id_lst.append(row[0]) + self.name_lst.append(row[1]) + self.pasta_lst.append(row[2]) + + + @subcommand(id={'description': "copypasta id"}) + async def byid(self, ctx: SlashContext, id: int) -> None: + """copypasta by id""" + for exist_id in self.id_lst: + if int(exist_id) == id: + await ctx.send(self.pasta_lst[self.id_lst.index(str(id))]) + return + await ctx.send("Not Found") + + + + + @subcommand(name={'description': "copypasta name"}) + async def byname(self, ctx: SlashContext, name: str) -> None: + """copypasta by name""" + for exist_name in self.name_lst: + if exist_name == name: + await ctx.send(self.pasta_lst[self.name_lst.index(name)]) + return + await ctx.send("Not Found") + + @byname.autocomplete("name") + async def find_name(self, ctx: interactions.AutocompleteContext): + '''Autocomplete that provides challenge categories for chal create''' + await ctx.send(self.name_lst) + + @subcommand() + async def random(self, ctx: SlashContext) -> None: + """random copypasta""" + await ctx.send(random.choice(self.pasta_lst))