-
Notifications
You must be signed in to change notification settings - Fork 0
/
content_merge_bot.py
73 lines (55 loc) · 2.25 KB
/
content_merge_bot.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
import discord
import os
import json
import io
from discord.ext import commands
from discord import PermissionOverwrite, Permissions
intents = discord.Intents.default()
intents.guilds = True
intents.messages = True
intents.message_content = True
bot = commands.Bot(command_prefix='$', intents=intents)
@bot.command()
async def merge(ctx, *channels: discord.TextChannel):
overwrites = {
ctx.guild.default_role: PermissionOverwrite(read_messages=False),
ctx.author: PermissionOverwrite(read_messages=True),
bot.user: PermissionOverwrite(read_messages=True)
}
new_channel = await ctx.guild.create_text_channel(
'merged-' + '-'.join(channel.name for channel in channels),
overwrites=overwrites
)
messages = []
for channel in channels:
async for message in channel.history(oldest_first=True):
content = f"{message.author.name} at {message.created_at} said:\n{message.content}"
files = await process_attachments(message.attachments)
messages.append((message.created_at.timestamp(), content, files))
messages.sort() # Sort messages by timestamp
for _, content, files in messages:
await new_channel.send(content=content, files=files if files else None)
async def process_attachments(attachments):
files = []
for attachment in attachments:
fp = io.BytesIO()
await attachment.save(fp)
files.append(discord.File(fp, filename=attachment.filename))
return files
@bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
@bot.command()
async def ping(ctx):
await ctx.send('pong')
@bot.event
async def on_command_error(ctx, error):
await ctx.send(f'An error occurred: {str(error)}')
with open('config.json') as config_file:
config = json.load(config_file)
bot.run(config['token'])
# intermediary step where we create a new dictionary where each post has a Unix timestamp
# It's cool to vent and stuff, but be aware of your own privacy needs in this growing server
# Don't be here looking for partners
# General
# Events --> Events becomes a category. Different channels for different types of events Beach night, Shows/clubs, Games/Magic?? , Tonight, Planning, Parties/get-togethers/high tea