-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscordify.py
86 lines (60 loc) · 2.34 KB
/
Discordify.py
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
import asyncio #for await, async events
import discord #discord.py for controlling the self-bot
from discord.ext import commands
import win32gui #for capturing window details from Spotify
import win32api
import tkinter #drawing error & warning windows
from tkinter import messagebox
import sys
def main():
longstring = """\
___ _ _ _ __
/ (_)___ ___ ___ _ __ __| (_)/ _|_ _
/ /\ / / __|/ __/ _ \| '__/ _` | | |_| | | |
/ /_//| \__ \ (_| (_) | | | (_| | | _| |_| |
/___,' |_|___/\___\___/|_| \__,_|_|_| \__, |
|___/
"""
print(longstring)
try:
token = read_token()
bot = commands.Bot(command_prefix=['m.'], self_bot=True)
bot.remove_command('help')
bot.loop.create_task(music_loop(bot))
bot.run(token, bot=False)
except discord.errors.LoginFailure as e:
root = tkinter.Tk()
root.withdraw()
root.iconbitmap('icon.ico')
messagebox.showwarning("Discordify",e)
sys.exit()
def read_token():
token = open('token.txt','r')
token = token.read()
if token == '':
root = tkinter.Tk()
root.withdraw()
root.iconbitmap('icon.ico')
messagebox.showerror("Discordify", "Error, Your Token.txt file is empty.")
else:
return token
async def music_loop(bot):
print('Awaiting bot until ready')
print(bot.wait_until_ready())
await bot.wait_until_ready()
await asyncio.sleep(1)
previousSong = ""
while not bot.is_closed:
currentSong = ''
windowID = win32gui.FindWindow("SpotifyMainWindow", None)
currentlyPlaying = win32gui.GetWindowText(windowID)
if currentlyPlaying != previousSong:
previousSong = currentlyPlaying
if currentlyPlaying == "" or currentlyPlaying == "Spotify":
await bot.change_presence(afk=True, status=discord.Status.invisible, game=None)
print('No Song is Currently Playing')
else:
print("Now Playing:",currentlyPlaying)
await bot.change_presence(afk=True,status=discord.Status.invisible,game=discord.Game(name=currentlyPlaying, type=2))
await asyncio.sleep(2)
main()