Last active
May 17, 2017 20:40
-
-
Save Emzi0767/ef67a065c56fbb3396544e93ec065b27 to your computer and use it in GitHub Desktop.
Overly fancy avatar update script, based on d.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import discord | |
import argparse | |
class AvatarClient(discord.Client): | |
def __init__(self, token: str, filename: str, username: str): | |
super().__init__() | |
self._av_token = token | |
self._av_filename = filename | |
self._av_username = username | |
async def on_ready(self): | |
print("Logged in as {}#{}".format(self.user.name, self.user.discriminator)) | |
if self._av_filename: | |
print("Updating avatar") | |
with open(self._av_filename, "rb") as fi: | |
f = fi.read() | |
await self.edit_profile(avatar=f) | |
print("Avatar updated") | |
if self._av_username: | |
print("Updating username") | |
await self.edit_profile(username=self._av_username) | |
print("Username updated") | |
await self.logout() | |
await self.close() | |
def do_dis_thang(self): | |
print("Logging in") | |
self.run(self._av_token) | |
def main(): | |
print("Initializing bot") | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-t", "--token", type=str, dest="token", help="Target's token", default=None) | |
parser.add_argument("-i", "--image-path", type=str, dest="image", help="Path to the new avatar", default=None) | |
parser.add_argument("-u", "--username", type=str, dest="username", help="New username", default=None) | |
args = parser.parse_args() | |
args = vars(args) | |
token = args["token"] | |
image = args["image"] | |
username = args["username"] | |
avu = AvatarClient(token, image, username) | |
avu.do_dis_thang() | |
print("All operations completed") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment