Skip to content

Commit d916b0e

Browse files
authored
Merge pull request #179 from AardWolf/dev
Prepare for October - rename profile
2 parents ef8f71c + c9cbc50 commit d916b0e

2 files changed

Lines changed: 72 additions & 16 deletions

File tree

untappd/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"author" : "Aardwolf98",
2+
"author" : ["Aardwolf98"],
33
"short" : "Perform simple Untappd lookups in chat",
44
"description" : "Allows simple commands for looking up beers and people within discord",
55
"disabled" : false,

untappd/untappd.py

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, bot):
4242
}
4343
self.config.register_global(**default_config)
4444
self.channels = {}
45-
self.is_chatty = False # Lets some debugging / annoying PMs happen
45+
self.is_chatty = False # Lets some debugging / annoying PMs happen
4646

4747
@commands.group(invoke_without_command=False)
4848
async def groupdrink(self, ctx):
@@ -712,7 +712,7 @@ async def lastbeer(self, ctx, profile: str = None):
712712
return
713713

714714
@commands.command()
715-
async def profile(self, ctx, profile: str = None):
715+
async def utprofile(self, ctx, profile: str = None):
716716
"""Search for a user's information by providing their profile name,
717717
discord mentions OK"""
718718

@@ -789,7 +789,7 @@ async def on_reaction_add(self, react: discord.Reaction, person: discord.User):
789789
"""
790790
emoji = react.emoji
791791
# Process the emoji
792-
eid = emoji.id if react.custom_emoji else str(emoji)
792+
# eid = emoji.id if react.custom_emoji else str(emoji)
793793
toast_emoji = await self.config.toast_emoji()
794794
if emoji == toast_emoji:
795795
# Find the checkin ID to use
@@ -808,7 +808,6 @@ async def on_reaction_add(self, react: discord.Reaction, person: discord.User):
808808
async def toast(self, ctx, *keywords):
809809
"""Toasts a checkin by number, if you're friends"""
810810

811-
author = ctx.author
812811
checkin = 0
813812

814813
for word in keywords:
@@ -984,16 +983,13 @@ async def ifound(self, ctx, *keywords):
984983
beers = await search_beer(self.config, ctx, keywords, limit=1)
985984
if isinstance(beers, str):
986985
await ctx.send(
987-
"Lookup of `{!s}` didn't result in a beer list: {!s}".
988-
format(keywords, beers)
986+
"Lookup of `{!s}` didn't result in a beer list: {!s}".format(keywords, beers)
989987
)
990988
return
991989
elif isinstance(beers["items"], list) and len(beers["items"]) > 0:
992990
beerid = beers["items"][0]["beer"]["bid"]
993991
else:
994-
await ctx.send(("Lookup of `{!s}` failed. So no, "
995-
"you haven't"
996-
).format(keywords))
992+
await ctx.send("Lookup of `{!s}` failed. So no, you haven't".format(keywords))
997993
return
998994

999995
if beerid:
@@ -1228,6 +1224,7 @@ async def ddp(self, ctx, checkin_id: int = 0):
12281224
avg_rating = beer["rating_score"]
12291225
total_checkins = beer["stats"]["total_user_count"]
12301226
abv = beer["beer_abv"]
1227+
beer_date = beer["created_at"]
12311228

12321229
# added for March 2019 -- collabs!
12331230
collabs = 0
@@ -1249,7 +1246,8 @@ async def ddp(self, ctx, checkin_id: int = 0):
12491246
"checkin_date": checkin_date,
12501247
"collabs": collabs,
12511248
"abv": abv,
1252-
"comment": comment
1249+
"comment": comment,
1250+
"beer_date": beer_date
12531251
}
12541252
async with aiohttp.ClientSession() as sess:
12551253
async with sess.post(url, data=payload) as resp:
@@ -1344,6 +1342,65 @@ async def undrank(self, ctx, checkin_id: int):
13441342
await ctx.send("Something went wrong adding the checkin")
13451343

13461344

1345+
@commands.command()
1346+
@commands.guild_only()
1347+
async def unfound(self, ctx, beer_id: int):
1348+
"""Removes a beer you found"""
1349+
1350+
author = ctx.author
1351+
url = ""
1352+
if ctx.guild:
1353+
guild = str(ctx.guild.id)
1354+
try:
1355+
url = await self.config.get_raw(guild, "project_url")
1356+
except KeyError:
1357+
pass
1358+
try:
1359+
profile = await self.config.get_raw(guild, author.id, "nick")
1360+
except KeyError:
1361+
profile = author.display_name
1362+
else:
1363+
profile = author.display_name
1364+
1365+
if not url:
1366+
await ctx.send("Looks like there are no projects right now")
1367+
return
1368+
1369+
payload = {
1370+
"action": "unfind",
1371+
"beerid": beer_id,
1372+
"username": profile
1373+
}
1374+
async with ctx.channel.typing():
1375+
async with aiohttp.ClientSession() as sess:
1376+
async with sess.post(url, data=payload) as resp:
1377+
if resp.status == 200:
1378+
try:
1379+
j = await resp.json()
1380+
except ValueError:
1381+
await ctx.send("Error somewhere in Google")
1382+
text = await resp.read()
1383+
print(text)
1384+
return
1385+
else:
1386+
return "Query failed with code " + str(resp.status)
1387+
1388+
if j['result'] == "success":
1389+
response_str = ""
1390+
if "message" in j:
1391+
response_str += j["message"] + " "
1392+
if "hasStats" in j:
1393+
response_str += "{} has {} points across {} checkins and {} found beers.".format(
1394+
j["username"], j["points"], j["checkins"], j["found"]
1395+
)
1396+
await ctx.send(response_str)
1397+
else:
1398+
if "message" in j:
1399+
await ctx.send(j["message"])
1400+
else:
1401+
await ctx.send("Something went un-finding the beer")
1402+
1403+
13471404
async def do_toast(config, author, checkin: int):
13481405
"""Toast a specific checkin"""
13491406

@@ -1510,7 +1567,7 @@ def beer_to_embed(beer, rating=None):
15101567
collab_str = ""
15111568
collabs = beer['collaborations_with']['items']
15121569
for num, collab in zip(range(10), collabs):
1513-
collab_str += "[" + collab['brewery']['brewery_name']
1570+
collab_str += num + " [" + collab['brewery']['brewery_name']
15141571
collab_str += "](https://untappd.com/brewery/"
15151572
collab_str += str(collab['brewery']['brewery_id']) + ")\n"
15161573
if len(collabs) > 10:
@@ -1816,7 +1873,7 @@ async def embed_menu(client, config, ctx, channels, beer_list: list, message, ti
18161873
await ctx.send("I didn't get a handle to an existing message.")
18171874
return
18181875

1819-
for num, beer in zip(range(1, limit + 1), beer_list):
1876+
for num, beer in zip(range(1, limit + 1), beer_list): # pylint: disable=unused-variable
18201877
emoji.append(EMOJI[num])
18211878
await message.add_reaction(EMOJI[num])
18221879

@@ -1826,8 +1883,7 @@ def check(reaction, person):
18261883
return False
18271884

18281885
try:
1829-
react, user = await client.wait_for(
1830-
'reaction_add', timeout=timeout, check=check)
1886+
react, user = await client.wait_for('reaction_add', timeout=timeout, check=check) # pylint: disable=unused-variable
18311887
except asyncio.TimeoutError:
18321888
# await ctx.send("Timed out, cleaning up")
18331889
try:
@@ -1939,7 +1995,7 @@ async def checkin_to_embed(config, ctx, channels, checkin):
19391995
if "collaborations_with" in beer:
19401996
collab_text = ""
19411997
collabs = beer['collaborations_with']['items']
1942-
for num, collab in zip(range(10), collabs):
1998+
for num, collab in zip(range(10), collabs): # pylint: disable=unused-variable
19431999
collab_text += "[" + collab['brewery']['brewery_name']
19442000
collab_text += "](https://untappd.com/brewery/"
19452001
collab_text += str(collab['brewery']['brewery_id']) + ")\n"

0 commit comments

Comments
 (0)