This repository has been archived by the owner on Jan 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
public-ideas-to-trello.py
executable file
·98 lines (77 loc) · 3.31 KB
/
public-ideas-to-trello.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
87
88
89
90
91
92
93
94
95
96
97
98
import json
import trello
import os
from discord.ext.commands import Bot
from datetime import datetime, timedelta
config = {
'discord_token': "Put Discord API Token here.",
'trello_api_key': "Put Trello API key here",
'trello_list_id': "Put the ID of the Trello list that new cards should be created in here",
'discord_channel_id': "Put the ID of the Discord channel you want to get public ideas from here",
'discord_reactions_message': "Put the ID of the message with all the reactions you want to purge here",
'rule_reminder_message': 'Put the ID of the message you want to be sent to remind people of the rules here',
'trello_api_secret': "Put your Trello secret here",
'trello_token': "Insert your Trello token here"
}
config_file = 'config.json'
if os.path.isfile(config_file):
with open(config_file) as f:
config.update(json.load(f))
with open('config.json', 'w') as f:
json.dump(config, f, indent='\t')
bot = Bot(command_prefix='t!')
trellobot = trello.TrelloClient(
api_key=config['trello_api_key'],
api_secret=config['trello_api_secret'],
token=config['trello_token']
)
async def description_reminder(ctx):
authors = []
async for message in ctx.channel.history(limit=20):
authors.append(message.author)
if bot.user not in authors:
what_to_send = await ctx.channel.get_message(id=config['rule_reminder_message'])
await ctx.channel.send(what_to_send.content)
@bot.event
async def on_ready():
print("Ready!")
@bot.event
async def on_message(message):
if message.author.bot:
return
await bot.process_commands(message)
if str(message.channel.id) == config['discord_channel_id']:
author_info = "{}#{} ({})".format(message.author.name, message.author.discriminator, message.author.id)
idea = message.clean_content
trellobot.get_list(config['trello_list_id']).add_card(idea, author_info)
await description_reminder(message)
await message.add_reaction('\N{SQUARED OK}')
@bot.event
async def on_message_edit(before, after):
if before.author.bot:
return
if str(before.channel.id) == config['discord_channel_id']:
card = trellobot.search(before.content)[0]
print(card)
card.set_name(after.content)
@bot.command()
async def testtrellosearch(ctx, what_to_search_for):
await ctx.send(trellobot.search(what_to_search_for))
@bot.command()
async def ping(ctx):
await ctx.send("Pong!")
@bot.command()
async def purge(ctx):
await ctx.send("Purging")
channel = ctx.guild.get_channel(config['discord_channel_id'])
print(config['discord_reactions_message'])
emoji = (await ctx.get_message(id=int(config['discord_reactions_message']))).content
print("Got emoji message as {}".format(emoji))
messages = [m async for m in channel.history(limit=None) if any(str(r.emoji) in emoji for r in m.reactions)]
bulk_cutoff = datetime.utcnow() - timedelta(days=14)
bulk_delete = [m for m in messages if m.created_at >= bulk_cutoff]
single_delete = [m for m in messages if m.created_at < bulk_cutoff]
coros = [channel.delete_messages(bulk_delete[i:i + 100]) for i in range(0, len(bulk_delete), 100)]
coros.extend(m.delete() for m in single_delete)
return len(bulk_delete), len(single_delete), len(coros)
bot.run(config['discord_token'])