aboutsummaryrefslogtreecommitdiff
path: root/cogs/general.py
blob: 9fc8f5cfd2cf754ec905d36d8bdcdba7bdc5b9c6 (plain) (blame)
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
from discord.ext import commands
import discord
import datetime
import requests
import json

def dump(obj):
	output = ""
	for attr in dir(obj):
		output += "\nobj.%s = %r" % (attr, getattr(obj, attr))
		print("obj.%s = %r" % (attr, getattr(obj, attr)))
	return output


class General(commands.Cog):
	def __init__(self, bot):
		self.bot = bot

	@commands.command()
	async def userinfo(self, ctx, user: discord.Member=None):
		#await ctx.send(f"```py\n{dump(user)}```")

		if not user:
			user = ctx.message.author

		output = ""
		for i in user.roles:
			output += i.mention + " "

		if user.color.value == 0:
			color = 16777210
		else:
			color = user.color

		embed=discord.Embed(title=user.name, description=user.mention, color=color, timestamp=ctx.message.created_at)
		#embed.set_thumbnail(url="attachment://temp.webp")
		embed.set_thumbnail(url=user.avatar_url_as(format="png"))
		embed.add_field(name="Nickname", value=user.display_name, inline=False)
		embed.add_field(name="Joined on", value=user.joined_at.date(), inline=True)
		embed.add_field(name="Status", value=user.status, inline=True)
		embed.add_field(name="Created account on", value=user.created_at.date(), inline=True)
		embed.add_field(name="Roles", value=output, inline=True)
		embed.set_footer(text=f"ID: {user.id}")
		await ctx.send(embed=embed)
		#os.remove("temp.webp")
		#os.remove("temp.png")

	@commands.command()
	async def coop(self, ctx, *, user: discord.Member=None):
		if not user:
			user = ctx.message.author
		else:
			user = self.bot.get_user(int(user))

		coop_role = ctx.guild.get_role(int(self.bot.config[str(ctx.message.guild.id)]["coop_roleID"]))

		if coop_role in user.roles:
			await user.remove_roles(coop_role)
			await ctx.send('You have left coop gang')
		else:
			await user.add_roles(coop_role)
			await ctx.send("You are now in the coop gang")

	@commands.command()
	async def serverinfo(self, ctx, guild=None):
		if not guild:
			guild = ctx.message.guild
		else:
			print(type(guild))
			guild = self.bot.get_guild(int(guild))

		if guild.owner.color.value == 0:
			color = 16777210
		else:
			color = guild.owner.color

		emojiList = " "
		for i in guild.emojis:
			emojiList += str(i) + " "

		embed=discord.Embed(title=guild.name, description=guild.description, color=color, timestamp=ctx.message.created_at)
		embed.set_thumbnail(url=guild.icon_url_as(format="png"))
		embed.set_image(url=guild.splash_url_as(format="png"))
		embed.add_field(name="Created on", value=guild.created_at.date(), inline=True)
		embed.add_field(name="Members", value=guild.member_count, inline=True)
		embed.add_field(name="Emojis", value=emojiList, inline=True)
		embed.add_field(name="Owner", value=guild.owner.mention, inline=True)
		embed.set_footer(text=f"ID: {guild.id}")
		await ctx.send(embed=embed)

	@commands.command()
	async def xboxUser(self, ctx, *, gamertag=None):
		if not gamertag:
			await ctx.send("You need to specify a gamer, gamer")
			return

		r = requests.get(f"https://xbl-api.prouser123.me/profile/gamertag/{gamertag}")
		gamer = json.loads(r.text)

		try:
			await ctx.send(f"{gamer['error']}: {gamer['message']}")
			return
		except KeyError:
			pass

		for i in gamer["profileUsers"][0]["settings"]:
			if i["id"] == "GameDisplayName":
				gameName = i["value"]
				continue
			if i["id"] == "AppDisplayPicRaw":
				picUrl = i["value"]
				continue
			if i["id"] == "Gamerscore":
				Gamerscore = i["value"]+"<:gamerscore:727131234534424586>"
				continue
			if i["id"] == "AccountTier":
				accountTier = i["value"]
				continue
			if i["id"] == "XboxOneRep":
				reputation = i["value"]
				continue
			if i["id"] == "PreferredColor":
				color = int(json.loads(requests.get(i["value"]).text)["primaryColor"], 16)
				continue
			if i["id"] == "Location":
				location = i["value"]
				continue
			if i["id"] == "Bio":
				#if len(i["value"]) == 0:
				#	Bio = "Unknown"
				#else:
				Bio = i["value"]
				continue
			if i["id"] == "Watermarks":
				Watermarks = i["value"]
				continue
			if i["id"] == "RealName":
				RealName = i["value"]
				continue


		embed=discord.Embed(title=gameName, description=Bio, color=color, timestamp=ctx.message.created_at)
		embed.set_thumbnail(url=picUrl)
		embed.add_field(name="Gamerscore", value=Gamerscore, inline=True)
		if len(location) != 0:
			embed.add_field(name="Location", value=location, inline=True)
		if len(Watermarks) != 0:
			embed.add_field(name="Watermarks", value=Watermarks, inline=True)
		embed.add_field(name="Account Tier", value=accountTier, inline=True)
		embed.add_field(name="Reputation", value=reputation, inline=True)
		await ctx.send(embed=embed)

def setup(bot):
	bot.add_cog(General(bot))