Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.

Commit e3a5baf

Browse files
author
dragdev
committed
Add one-way
Signed-off-by: dragdev <samueljohnnicholson@gmail.com>
1 parent 063def0 commit e3a5baf

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

riftgun/oneway.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import discord
2+
from discord.ext import commands
3+
4+
from .cog import RiftGun
5+
6+
7+
class OneWayRiftGun(RiftGun):
8+
"""The rift gun, but one-way instead."""
9+
10+
@commands.Cog.listener(name="on_message")
11+
async def message(self, message: discord.Message):
12+
context: commands.Context = await self.bot.get_context(message)
13+
if message.author == self.bot.user:
14+
return # only ignore the current bot to prevent loops.
15+
elif context.valid:
16+
return
17+
18+
sources = {}
19+
targets = {}
20+
sid = message.channel.id
21+
22+
for target, source in self.data.items():
23+
sources[int(source["source"])] = int(target)
24+
targets[int(target)] = int(source["source"])
25+
26+
if sid in targets.keys():
27+
channel = self.bot.get_channel(targets[sid])
28+
attachments = [a.to_file() for a in message.attachments]
29+
await channel.send(f"**{message.author}:** {message.clean_content}"[:2000],
30+
embed=message.embeds[0] if message.embeds else None,
31+
files=attachments or None)
32+
33+
34+
def setup(bot: commands.Bot):
35+
if bot.get_cog("RiftGun"):
36+
bot.unload_extension("riftgun")
37+
bot.add_cog(OneWayRiftGun(bot))

0 commit comments

Comments
 (0)