├── LICENSE ├── README.md ├── bot_generator.py ├── codes.txt └── logs.txt /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Chasa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Code Generator 2 | You know those servers with "generator" bots, like `!gen nordvpn`? This is the code for them. 3 | 4 | ### How it works: 5 | * You add codes/logins/whatever in a file. 6 | * People with the role can do -generate and get a random code from the file. 7 | * It removes the code and sends it to the user. 8 | * They have a cooldown of x amount of time. 9 | 10 | ### Features 11 | * Logging: Every single thing that happens is logged in a file. 12 | * Everything is customisable. 13 | 14 | If you have anything you'd like to add or just want to talk to people who are similar minded, join my [Discord Server](https://chasa.wtf). 15 | 16 | Join my discord. :) 17 | -------------------------------------------------------------------------------- /bot_generator.py: -------------------------------------------------------------------------------- 1 | # Config 2 | # If you know what your doing, feel free to edit the code. 3 | 4 | # Bot Token 5 | # Token of the Bot which you want to use. 6 | TOKEN = "" 7 | 8 | # Log File 9 | # Where all the logs of everything are stored. 10 | # Default: "logs.txt" 11 | LOG_FILE = "logs.txt" 12 | 13 | # File where the codes are stored. 14 | # Codes are given out by lines, so make sure they are split line by line. 15 | # Default: "codes.txt" 16 | CODES_FILE = "codes.txt" 17 | 18 | # Role ID 19 | # This is the ID of the role which is allowed to use the gen. 20 | ROLE_ID = 867366769392091157 21 | 22 | # Cooldown 23 | # This is the seconds cooldown each user has per usage. 24 | # 86400 is a day / 3600 is an hour 25 | COOLDOWN = 86400 26 | 27 | # imports here 28 | import asyncio 29 | import discord 30 | from discord.ext import commands 31 | import random 32 | import aiofiles 33 | import time 34 | from datetime import datetime 35 | from colorama import Fore, init 36 | 37 | init(autoreset=True) 38 | gen_role = None 39 | bot = commands.Bot(command_prefix="-", intents=discord.Intents.all(), case_insensitive=True) # prefix here 40 | 41 | async def getEmbed(type, arg=None): # change colours if you want to here 42 | if type == 0: 43 | embed = discord.Embed(title="Sent you a code.", description="Check your DMs.", colour=discord.Colour.green()) 44 | return embed 45 | elif type == 1: 46 | embed = discord.Embed(title="Here's your Generated Code.", description=arg, colour=discord.Colour.blue()) 47 | return embed 48 | elif type == 2: 49 | embed = discord.Embed(title="Out of stock.", description="Generator is out of stock.", colour=discord.Colour.red()) 50 | return embed 51 | elif type == 3: 52 | embed = discord.Embed(title="Timeout.", description=f"You are on timeout, retry in **{arg}**.", colour=discord.Colour.red()) 53 | return embed 54 | elif type == 4: 55 | embed = discord.Embed(title="No Perms.", description=f"You do not have permission to execute this command.", colour=discord.Colour.red()) 56 | return embed 57 | 58 | async def convert(seconds): 59 | seconds = seconds % (24 * 3600) 60 | hour = seconds // 3600 61 | seconds %= 3600 62 | minutes = seconds // 60 63 | seconds %= 60 64 | return "%dh %2dm %2ds" % (hour, minutes, seconds) 65 | 66 | async def log(event, user=None, info=None): # logging in log.txt if you want to edit them 67 | now = datetime.now() 68 | timedata = f"{now.strftime('%Y-%m-%d %H:%M:%S')}" 69 | 70 | writeable = "" 71 | 72 | if event == "generated": 73 | writeable += "[ GENERATE ] " 74 | elif event == "cooldown": 75 | writeable += "[ COOLDOWN ] " 76 | elif event == "no stock": 77 | writeable += "[ NO STOCK ] " 78 | elif event == "no dms": 79 | writeable += "[ NO DMS ] " 80 | elif event == "bootup": 81 | writeable += "\n[ BOOTUP ] " 82 | elif event == "ping": 83 | writeable += "[ PING ] " 84 | elif event == "no perms": 85 | writeable += "[ NO PERMS ] " 86 | elif event == "userinfo": 87 | writeable += "[ USERINFO ] " 88 | elif event == "error": 89 | writeable += "[ CRITICAL ] " 90 | 91 | writeable += timedata 92 | 93 | try: 94 | writeable += f" ID: {user.id} User: {user.name}#{user.discriminator} // " 95 | except: 96 | writeable += f" // " 97 | 98 | if event == "generated": 99 | info = info.strip('\n') 100 | writeable += f"User was successfully sent code: {info}" 101 | elif event == "cooldown": 102 | writeable += f"User couldn't be sent a code as they are on a cooldown of {info}." 103 | elif event == "no stock": 104 | writeable += f"User couldn't be sent a code as there is no stock." 105 | elif event == "no dms": 106 | writeable += f"User couldn't be sent a code as their DMs were disabled." 107 | elif event == "bootup": 108 | writeable += "Bot was turned on." 109 | elif event == "ping": 110 | writeable += "User used the ping command." 111 | elif event == "no perms": 112 | writeable += f"User does not have the significant permissions for the {info} command." 113 | elif event == "userinfo": 114 | writeable += f"User used the userinfo command on: {info}" 115 | elif event == "error": 116 | writeable += info 117 | 118 | async with aiofiles.open(LOG_FILE, mode="a") as file: 119 | await file.write(f"\n{writeable}") 120 | 121 | if writeable.startswith("[ NO STOCK ]"): 122 | print(Fore.LIGHTYELLOW_EX + writeable.strip('\n')) 123 | elif writeable.startswith("[ CRITICAL ]"): 124 | for x in range(3): 125 | print(Fore.LIGHTRED_EX + writeable.strip('\n')) 126 | elif writeable.startswith("[ BOOTUP ]"): 127 | print(Fore.LIGHTGREEN_EX + writeable.strip('\n')) 128 | 129 | @bot.event 130 | async def on_ready(): 131 | global gen_role 132 | try: 133 | open(LOG_FILE, "x").close() 134 | except: 135 | pass 136 | try: 137 | open(CODES_FILE, "x").close() 138 | except: 139 | pass 140 | await log("bootup") 141 | for guild in bot.guilds: 142 | role = guild.get_role(ROLE_ID) 143 | if role != None: 144 | gen_role = role 145 | break 146 | if gen_role == None: 147 | await log("error", user=None, info=f"Cannot fetch role ({ROLE_ID}) from {bot.guilds[0].name}. Exiting in 5 seconds.") 148 | await asyncio.sleep(5) 149 | exit() 150 | 151 | @bot.event 152 | async def on_command_error(ctx, error): 153 | if isinstance(error, commands.CommandOnCooldown): 154 | time_retry = await convert(error.retry_after) 155 | await ctx.send(content = ctx.author.mention, embed = await getEmbed(3, time_retry)) 156 | await log("cooldown", ctx.author, time_retry) 157 | elif isinstance(error, commands.MissingRole): 158 | await ctx.send(content = ctx.author.mention, embed = await getEmbed(4)) 159 | await log("no perms", ctx.author, "generate") 160 | 161 | @bot.command() 162 | @commands.cooldown(1, COOLDOWN) # 1 is codes per cooldown // 86400 is the cooldown time (is in second) 163 | @commands.has_role(ROLE_ID) # role for gen perms 164 | @commands.guild_only() 165 | async def generate(ctx): 166 | try: 167 | dm_msg = await ctx.author.send("Processing your request...") 168 | except: 169 | embed = discord.Embed(title="DMs are disabled!", description="Your dms are disabled. Enable them in Privacy Settings.", colour=discord.Colour.red()) 170 | embed.set_image(url="https://cdn.discordapp.com/attachments/829087959331897364/850841491470548992/ezgif-2-ca6ebd5d9cfb.gif") 171 | await ctx.send(content=ctx.author.mention, embed=embed) 172 | await log("no dms", ctx.author) 173 | return 174 | async with aiofiles.open("codes.txt", mode="r") as file: # name of codes file 175 | file_lines = await file.readlines() 176 | try: 177 | code = random.choice(file_lines) 178 | except: 179 | await dm_msg.edit(embed=await getEmbed(type=2), content=ctx.author.mention) 180 | await ctx.send(embed=await getEmbed(type=2), content=ctx.author.mention) 181 | bot.get_command("generate").reset_cooldown(ctx) 182 | await log("no stock", ctx.author) 183 | return 184 | else: 185 | file_lines.remove(code) 186 | async with aiofiles.open("codes.txt", mode="w") as file: # name of codes file 187 | for line in file_lines: 188 | if file_lines[-1] != line: 189 | await file.write(line) 190 | else: 191 | await file.write(line.strip("\n")) 192 | await dm_msg.edit(embed=await getEmbed(type=1,arg=code), content=ctx.author.mention) 193 | await ctx.send(embed=await getEmbed(type=0), content=ctx.author.mention) 194 | await log("generated", ctx.author, code) 195 | 196 | @bot.command() 197 | async def userinfo(ctx, *, user : discord.Member = None): 198 | if user == None: 199 | user = ctx.author 200 | 201 | if gen_role in user.roles: 202 | des = f"Generator: `🟢`" 203 | else: 204 | des = f"Generator: `🔴`" 205 | 206 | embed = discord.Embed(color=discord.Colour.blue(), description=des, title=" ") 207 | embed.set_author(name=f"{user.name}#{user.discriminator}", icon_url=user.default_avatar_url) 208 | await ctx.send(embed=embed, content=ctx.author.mention) 209 | await log("userinfo", user=ctx.author, info=f"{user.name}#{user.discriminator}") 210 | 211 | @bot.command() 212 | async def ping(ctx): 213 | embed = discord.Embed(title="Response Times", color=discord.Colour.blue()) # colour of ping command 214 | embed.add_field(name="API", value=f"`Loading...`") 215 | embed.add_field(name="Websocket", value=f"`{int(bot.latency * 1000)}ms`") 216 | time_before = time.time() 217 | edit = await ctx.send(embed=embed, content=f"{ctx.author.mention}") 218 | time_after = time.time() 219 | difference = int((time_after - time_before) * 1000) 220 | embed = discord.Embed(title="Response Times", color=discord.Colour.green()) # colour of ping command 221 | embed.add_field(name="API", value=f"`{difference}ms`") 222 | embed.add_field(name="Websocket", value=f"`{int(bot.latency * 1000)}ms`") 223 | await edit.edit(embed=embed, content=f"{ctx.author.mention}") 224 | await log("ping", ctx.author) 225 | 226 | bot.run(TOKEN) 227 | -------------------------------------------------------------------------------- /codes.txt: -------------------------------------------------------------------------------- 1 | example1@gmail.com:example1 2 | example2@gmail.com:example2 -------------------------------------------------------------------------------- /logs.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | [ BOOTUP ] 2021-07-21 12:26:49 // Bot was turned on. 4 | [ USERINFO ] 2021-07-21 12:26:55 ID: 864250923692851210 User: Chasa#4490 // User used the userinfo command on: Chasa#4490 5 | [ NO PERMS ] 2021-07-21 12:27:20 ID: 864250923692851210 User: Chasa#4490 // User does not have the significant permissions for the generate command. 6 | [ PING ] 2021-07-21 12:27:31 ID: 864250923692851210 User: Chasa#4490 // User used the ping command. 7 | [ PING ] 2021-07-21 12:27:45 ID: 864250923692851210 User: Chasa#4490 // User used the ping command. 8 | 9 | [ BOOTUP ] 2021-07-21 12:28:05 // Bot was turned on. 10 | [ CRITICAL ]2021-07-21 12:28:05 // Cannot fetch role (8673667693920911571) from Chasa's server. Exiting in 5 seconds. 11 | 12 | [ BOOTUP ] 2021-07-21 12:28:23 // Bot was turned on. 13 | [ CRITICAL ] 2021-07-21 12:28:23 // Cannot fetch role (8673667693920911571) from Chasa's server. Exiting in 5 seconds. 14 | 15 | [ BOOTUP ] 2021-07-21 12:28:39 // Bot was turned on. 16 | [ USERINFO ] 2021-07-21 12:28:55 ID: 864250923692851210 User: Chasa#4490 // User used the userinfo command on: Chasa#4490 17 | [ USERINFO ] 2021-07-21 12:29:07 ID: 864250923692851210 User: Chasa#4490 // User used the userinfo command on: Chasa#4490 18 | [ NO STOCK ] 2021-07-21 12:29:16 ID: 864250923692851210 User: Chasa#4490 // User couldn't be sent a code as there is no stock. 19 | [ USERINFO ] 2021-07-21 12:29:48 ID: 864250923692851210 User: Chasa#4490 // User used the userinfo command on: Chasa#4490 20 | 21 | [ BOOTUP ] 2021-07-21 12:30:37 // Bot was turned on. 22 | [ USERINFO ] 2021-07-21 12:30:38 ID: 864250923692851210 User: Chasa#4490 // User used the userinfo command on: Chasa#4490 23 | [ USERINFO ] 2021-07-21 12:30:44 ID: 864250923692851210 User: Chasa#4490 // User used the userinfo command on: Chasa#4490 24 | [ NO STOCK ] 2021-07-21 12:30:52 ID: 864250923692851210 User: Chasa#4490 // User couldn't be sent a code as there is no stock. --------------------------------------------------------------------------------