mirror of
https://github.com/nexus-stc/hyperboria
synced 2025-01-24 01:17:35 +01:00
43be16e4bc
- [nexus] Remove outdated protos - [nexus] Development - [nexus] Development - [nexus] Development - [nexus] Development - [nexus] Development - [nexus] Refactor views - [nexus] Update aiosumma - [nexus] Add tags - [nexus] Development - [nexus] Update repository - [nexus] Update repository - [nexus] Update dependencies - [nexus] Update dependencies - [nexus] Fixes for MetaAPI - [nexus] Support for new queries - [nexus] Adopt new versions of search - [nexus] Improving Nexus - [nexus] Various fixes - [nexus] Add profile - [nexus] Fixes for ingestion - [nexus] Refactorings and bugfixes - [idm] Add profile methods - [nexus] Fix stalled nexus-meta bugs - [nexus] Various bugfixes - [nexus] Restore IDM API functionality GitOrigin-RevId: a0842345a6dde5b321279ab5510a50c0def0e71a
82 lines
2.6 KiB
Python
82 lines
2.6 KiB
Python
from typing import Optional
|
|
|
|
from .base_view_builder import (
|
|
BaseButtonsBuilder,
|
|
BaseViewBuilder,
|
|
highlight_markdown,
|
|
)
|
|
|
|
|
|
class ScitechButtonsBuilder(BaseButtonsBuilder):
|
|
def add_default_layout(self, bot_name, session_id, position: int = 0):
|
|
return (
|
|
self.add_download_button(session_id, position)
|
|
.add_close_button(session_id)
|
|
)
|
|
|
|
|
|
class ScitechViewBuilder(BaseViewBuilder):
|
|
icon = '📚'
|
|
|
|
def add_edition(self, with_brackets=True, bold=False):
|
|
edition = self.document_holder.edition
|
|
if edition:
|
|
if edition.isdigit():
|
|
if edition[-1] == '1':
|
|
edition += 'st edition'
|
|
elif edition[-1] == '2':
|
|
edition += 'nd edition'
|
|
elif edition[-1] == '3':
|
|
edition += 'rd edition'
|
|
else:
|
|
edition += 'th edition'
|
|
return self.add(edition, with_brackets=with_brackets, bold=bold)
|
|
|
|
def add_pages(self):
|
|
if self.document_holder.pages:
|
|
self.add(f'pp. {self.document_holder.pages}')
|
|
return self
|
|
|
|
def add_title(self, bold=True):
|
|
title = self.document_holder.title or ''
|
|
if self.document_holder.periodical:
|
|
if title:
|
|
title += f' ({self.document_holder.periodical})'
|
|
else:
|
|
title += self.document_holder.periodical
|
|
elif self.document_holder.volume:
|
|
if title:
|
|
title += f' ({self.document_holder.volume})'
|
|
else:
|
|
title += self.document_holder.volume
|
|
self.add(title, bold=bold)
|
|
self.add_edition(with_brackets=True, bold=bold)
|
|
return self
|
|
|
|
def add_snippet(self, on_newline=True):
|
|
snippet = self.document_holder.snippets.get('description')
|
|
if snippet and snippet.highlights:
|
|
if on_newline:
|
|
self.add_new_line()
|
|
self.add(highlight_markdown(snippet), escaped=True)
|
|
return self
|
|
|
|
def add_locator(self, first_n_authors=1, markup=True):
|
|
return (
|
|
self.add_authors(first_n_authors=first_n_authors, on_newline=True)
|
|
.add_formatted_datetime()
|
|
)
|
|
|
|
def add_filedata(self, with_leading_pipe=False):
|
|
filedata = self.document_holder.get_formatted_filedata()
|
|
if filedata:
|
|
if with_leading_pipe:
|
|
self.add('|')
|
|
self.add(filedata)
|
|
return self
|
|
|
|
def add_description(self, limit: Optional[int] = None):
|
|
if self.document_holder.description:
|
|
self.add(self.document_holder.description)
|
|
return self
|